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 | |
parent | 01773c71a4698c6f01fe70d864f922bda65506cb (diff) | |
download | plus-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.tar.gz plus-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.tar.bz2 plus-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.tar.xz plus-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.zip |
Add strong typed int type BeingId.
Diffstat (limited to 'src')
153 files changed, 881 insertions, 627 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f84b8fc2b..472bbac8a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1057,6 +1057,7 @@ SET(SRCS enums/state.h enums/simpletypes/allowsort.h enums/simpletypes/allplayers.h + enums/simpletypes/beingid.h enums/simpletypes/booldefines.h enums/simpletypes/damaged.h enums/simpletypes/enable.h diff --git a/src/Makefile.am b/src/Makefile.am index 98ce8fecc..2fe46a3db 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1186,6 +1186,7 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ enums/state.h \ enums/simpletypes/allowsort.h \ enums/simpletypes/allplayers.h \ + enums/simpletypes/beingid.h \ enums/simpletypes/booldefines.h \ enums/simpletypes/damaged.h \ enums/simpletypes/enable.h \ diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp index a666d01a2..0b8e8aedc 100644 --- a/src/actions/actions.cpp +++ b/src/actions/actions.cpp @@ -480,7 +480,8 @@ impHandler(heal) const Being *being = nullptr; if (args[0] == ':') { - being = actorManager->findBeing(atoi(args.substr(1).c_str())); + being = actorManager->findBeing(fromInt(atoi( + args.substr(1).c_str()), BeingId)); if (being && being->getType() == ActorType::Monster) being = nullptr; } @@ -588,7 +589,8 @@ impHandler(pickup) } else { - FloorItem *const item = actorManager->findItem(atoi(args.c_str())); + FloorItem *const item = actorManager->findItem(fromInt( + atoi(args.c_str()), BeingId)); if (item) localPlayer->pickUp(item); } @@ -758,7 +760,8 @@ impHandler(attack) } else { - target = actorManager->findBeing(atoi(args.substr(1).c_str())); + target = actorManager->findBeing(fromInt(atoi( + args.substr(1).c_str()), BeingId)); if (target && target->getType() != ActorType::Monster) target = nullptr; } @@ -789,7 +792,8 @@ impHandler(targetAttack) } else { - target = actorManager->findBeing(atoi(args.substr(1).c_str())); + target = actorManager->findBeing(fromInt(atoi( + args.substr(1).c_str()), BeingId)); if (target && target->getType() != ActorType::Monster) target = nullptr; } @@ -1599,9 +1603,14 @@ impHandler(kick) if (!args.empty()) { if (args[0] != ':') + { target = actorManager->findNearestByName(args); + } else - target = actorManager->findBeing(atoi(args.substr(1).c_str())); + { + target = actorManager->findBeing(fromInt(atoi( + args.substr(1).c_str()), BeingId)); + } } if (!target) target = localPlayer->getTarget(); diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp index 9ec4ca28f..0bcca016c 100644 --- a/src/actions/commands.cpp +++ b/src/actions/commands.cpp @@ -254,7 +254,7 @@ impHandler(chatNuke) if (!being) return true; - actorManager->addBlock(static_cast<uint32_t>(being->getId())); + actorManager->addBlock(being->getId()); actorManager->destroy(being); return true; } @@ -268,7 +268,7 @@ impHandler(chatAdd) return true; const int id = atoi(event.args.c_str()); - if (!id) + if (id == 0) return true; Inventory *const inv = PlayerInfo::getInventory(); @@ -286,7 +286,8 @@ impHandler(chatAdd) return true; } - const FloorItem *const floorItem = actorManager->findItem(id); + const FloorItem *const floorItem = actorManager->findItem( + fromInt(id, BeingId)); if (floorItem) { diff --git a/src/actions/pets.cpp b/src/actions/pets.cpp index a31e8aadc..a6c9a24df 100644 --- a/src/actions/pets.cpp +++ b/src/actions/pets.cpp @@ -66,8 +66,8 @@ static const Being *getPet() } #endif #ifdef EATHENA_SUPPORT - const int id = PlayerInfo::getPetBeingId(); - if (!id) + const BeingId id = PlayerInfo::getPetBeingId(); + if (id == BeingId_zero) return nullptr; return actorManager->findBeing(id); #else diff --git a/src/actormanager.cpp b/src/actormanager.cpp index fb1217e87..4544e445f 100644 --- a/src/actormanager.cpp +++ b/src/actormanager.cpp @@ -238,7 +238,7 @@ void ActorManager::setPlayer(LocalPlayer *const player) socialWindow->updatePickupFilter(); } -Being *ActorManager::createBeing(const int id, +Being *ActorManager::createBeing(const BeingId id, const ActorType::Type type, const uint16_t subtype) { @@ -280,7 +280,8 @@ Being *ActorManager::createBeing(const int id, return being; } -FloorItem *ActorManager::createItem(const int id, const int itemId, +FloorItem *ActorManager::createItem(const BeingId id, + const int itemId, const int x, const int y, const int amount, const unsigned char color, @@ -327,7 +328,7 @@ void ActorManager::undelete(const ActorSprite *const actor) } } -Being *ActorManager::findBeing(const int id) const +Being *ActorManager::findBeing(const BeingId id) const { for_actors { @@ -539,7 +540,7 @@ Being *ActorManager::findPortalByTile(const int x, const int y) const return nullptr; } -FloorItem *ActorManager::findItem(const int id) const +FloorItem *ActorManager::findItem(const BeingId id) const { for_actorsm { @@ -1337,17 +1338,17 @@ bool ActorManager::hasActorSprite(const ActorSprite *const actor) const return false; } -void ActorManager::addBlock(const uint32_t id) +void ActorManager::addBlock(const BeingId id) { mBlockedBeings.insert(id); } -void ActorManager::deleteBlock(const uint32_t id) +void ActorManager::deleteBlock(const BeingId id) { mBlockedBeings.erase(id); } -bool ActorManager::isBlocked(const uint32_t id) const +bool ActorManager::isBlocked(const BeingId id) const { return mBlockedBeings.find(id) != mBlockedBeings.end(); } @@ -1795,7 +1796,8 @@ Being *ActorManager::cloneBeing(const Being *const srcBeing, const int dx, const int dy, const int id) { - Being *const dstBeing = actorManager->createBeing(srcBeing->getId() + id, + Being *const dstBeing = actorManager->createBeing(fromInt( + toInt(srcBeing->getId(), int) + id, BeingId), ActorType::Player, srcBeing->getSubType()); if (!dstBeing) diff --git a/src/actormanager.h b/src/actormanager.h index 08e1d005e..073a5a025 100644 --- a/src/actormanager.h +++ b/src/actormanager.h @@ -27,6 +27,7 @@ #include "enums/simpletypes/allowsort.h" #include "enums/simpletypes/allplayers.h" +#include "enums/simpletypes/beingid.h" #include "enums/simpletypes/npcnames.h" #include "listeners/configlistener.h" @@ -68,7 +69,7 @@ class ActorManager final: public ConfigListener /** * Create a Being and add it to the list of ActorSprites. */ - Being *createBeing(const int id, + Being *createBeing(const BeingId id, const ActorType::Type type, const uint16_t subtype) A_WARN_UNUSED; @@ -79,9 +80,11 @@ class ActorManager final: public ConfigListener /** * Create a FloorItem and add it to the list of ActorSprites. */ - FloorItem *createItem(const int id, const int itemId, + FloorItem *createItem(const BeingId id, + const int itemId, const int x, const int y, - const int amount, const unsigned char color, + const int amount, + const unsigned char color, const int subX, const int subY); /** @@ -97,7 +100,7 @@ class ActorManager final: public ConfigListener /** * Returns a specific Being, by id; */ - Being *findBeing(const int id) const A_WARN_UNUSED; + Being *findBeing(const BeingId id) const A_WARN_UNUSED; /** * Returns a being at specific coordinates. @@ -127,7 +130,7 @@ class ActorManager final: public ConfigListener /** * Returns a specific FloorItem, by id. */ - FloorItem *findItem(const int id) const A_WARN_UNUSED; + FloorItem *findItem(const BeingId id) const A_WARN_UNUSED; /** * Returns a FloorItem at specific coordinates. @@ -223,11 +226,11 @@ class ActorManager final: public ConfigListener */ void clear(); - void addBlock(const uint32_t id); + void addBlock(const BeingId id); - void deleteBlock(const uint32_t id); + void deleteBlock(const BeingId id); - bool isBlocked(const uint32_t id) const; + bool isBlocked(const BeingId id) const; void printAllToChat() const; @@ -352,7 +355,7 @@ class ActorManager final: public ConfigListener ActorSprites mActors; ActorSprites mDeleteActors; - std::set<uint32_t> mBlockedBeings; + std::set<BeingId> mBlockedBeings; Map *mMap; std::string mSpellHeal1; std::string mSpellHeal2; diff --git a/src/avatar.cpp b/src/avatar.cpp index 82ac000ba..1045fe6be 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -25,7 +25,7 @@ #include "debug.h" Avatar::Avatar(const std::string &name) : - mId(0), + mId(BeingId_zero), mCharId(0), mName(name), mOriginalName(name), diff --git a/src/avatar.h b/src/avatar.h index a8e690b29..f079e367f 100644 --- a/src/avatar.h +++ b/src/avatar.h @@ -25,6 +25,8 @@ #include "enums/being/gender.h" +#include "enums/simpletypes/beingid.h" + #include <string> #include "localconsts.h" @@ -144,10 +146,10 @@ class Avatar notfinal void setExp(const int n) { mExp = n; } - int getID() const A_WARN_UNUSED + BeingId getID() const A_WARN_UNUSED { return mId; } - void setID(const int id) + void setID(const BeingId id) { mId = id; } int getCharId() const A_WARN_UNUSED @@ -181,7 +183,7 @@ class Avatar notfinal { mPoison = b; } protected: - int mId; + BeingId mId; int mCharId; std::string mName; std::string mOriginalName; diff --git a/src/being/actorsprite.cpp b/src/being/actorsprite.cpp index 0def1ea5b..b7e30cacd 100644 --- a/src/being/actorsprite.cpp +++ b/src/being/actorsprite.cpp @@ -56,7 +56,7 @@ AnimatedSprite *ActorSprite::targetCursor[TargetCursorType::NUM_TCT] [TargetCursorSize::NUM_TC]; bool ActorSprite::loaded = false; -ActorSprite::ActorSprite(const int id) : +ActorSprite::ActorSprite(const BeingId id) : CompoundSprite(), Actor(), mStatusEffects(), diff --git a/src/being/actorsprite.h b/src/being/actorsprite.h index bc7aca3ee..9e676193e 100644 --- a/src/being/actorsprite.h +++ b/src/being/actorsprite.h @@ -32,6 +32,7 @@ #include "enums/being/targetcursorsize.h" #include "enums/being/targetcursortype.h" +#include "enums/simpletypes/beingid.h" #include "enums/simpletypes/enable.h" #include "enums/simpletypes/forcedisplay.h" @@ -49,16 +50,16 @@ struct SpriteDisplay; class ActorSprite notfinal : public CompoundSprite, public Actor { public: - explicit ActorSprite(const int id); + explicit ActorSprite(const BeingId id); A_DELETE_COPY(ActorSprite) virtual ~ActorSprite(); - int getId() const A_WARN_UNUSED + BeingId getId() const A_WARN_UNUSED { return mId; } - void setId(const int id) + void setId(const BeingId id) { mId = id; } /** @@ -224,7 +225,7 @@ class ActorSprite notfinal : public CompoundSprite, public Actor ParticleList mStunParticleEffects; ParticleVector mStatusParticleEffects; ParticleList mChildParticleEffects; - int mId; + BeingId mId; uint16_t mStunMode; /**< Stun mode; zero if not stunned */ /** Target cursor being used */ diff --git a/src/being/being.cpp b/src/being/being.cpp index 482dd14eb..6c3962e7b 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -125,7 +125,7 @@ std::list<BeingCacheEntry*> beingInfoCache; typedef std::map<int, Guild*>::const_iterator GuildsMapCIter; typedef std::map<int, int>::const_iterator IntMapCIter; -Being::Being(const int id, +Being::Being(const BeingId id, const ActorType::Type type, const uint16_t subtype, Map *const map) : @@ -333,7 +333,7 @@ void Being::setSubtype(const uint16_t subtype, const uint16_t look) if (mType == ActorType::Monster) { - mInfo = MonsterDB::get(mSubType); + mInfo = MonsterDB::get(fromInt(mSubType, BeingId)); if (mInfo) { setName(mInfo->getName()); @@ -347,7 +347,7 @@ void Being::setSubtype(const uint16_t subtype, const uint16_t look) #ifdef EATHENA_SUPPORT if (mType == ActorType::Pet) { - mInfo = PETDB::get(mSubType); + mInfo = PETDB::get(fromInt(mSubType, BeingId)); if (mInfo) { setName(mInfo->getName()); @@ -360,7 +360,7 @@ void Being::setSubtype(const uint16_t subtype, const uint16_t look) } else if (mType == ActorType::Mercenary) { - mInfo = MercenaryDB::get(mSubType); + mInfo = MercenaryDB::get(fromInt(mSubType, BeingId)); if (mInfo) { setName(mInfo->getName()); @@ -373,7 +373,7 @@ void Being::setSubtype(const uint16_t subtype, const uint16_t look) } if (mType == ActorType::Homunculus) { - mInfo = HomunculusDB::get(mSubType); + mInfo = HomunculusDB::get(fromInt(mSubType, BeingId)); if (mInfo) { setName(mInfo->getName()); @@ -387,7 +387,7 @@ void Being::setSubtype(const uint16_t subtype, const uint16_t look) #endif else if (mType == ActorType::Npc) { - mInfo = NPCDB::get(mSubType); + mInfo = NPCDB::get(fromInt(mSubType, BeingId)); if (mInfo) { setupSpriteDisplay(mInfo->getDisplay(), ForceDisplay_false); @@ -396,7 +396,7 @@ void Being::setSubtype(const uint16_t subtype, const uint16_t look) } else if (mType == ActorType::Avatar) { - mInfo = AvatarDB::get(mSubType); + mInfo = AvatarDB::get(fromInt(mSubType, BeingId)); if (mInfo) setupSpriteDisplay(mInfo->getDisplay(), ForceDisplay_false); } @@ -1680,7 +1680,7 @@ void Being::petLogic() setAction(BeingAction::STAND, 0); fixPetSpawnPos(dstX, dstY); setTileCoords(dstX, dstY); - petHandler->spawn(mOwner, mId, dstX, dstY); + //petHandler->spawn(mOwner, mId, dstX, dstY); mPetAi = true; } else if (!followDist || divX > followDist || divY > followDist) @@ -2189,8 +2189,8 @@ void Being::setSprite(const unsigned int slot, const int id, const ItemInfo &info = ItemDB::get(id1); if (!isTempSprite && mMap && mType == ActorType::Player) { - const int pet = info.getPet(); - if (pet) + const BeingId pet = fromInt(info.getPet(), BeingId); + if (pet != BeingId_zero) removePet(pet); } removeItemParticles(id1); @@ -2204,8 +2204,8 @@ void Being::setSprite(const unsigned int slot, const int id, if (!isTempSprite && mType == ActorType::Player) { - const int pet = info.getPet(); - if (pet) + const BeingId pet = fromInt(info.getPet(), BeingId); + if (pet != BeingId_zero) addPet(pet); } @@ -2428,7 +2428,7 @@ void Being::addToCache() const } } -BeingCacheEntry* Being::getCacheEntry(const int id) +BeingCacheEntry* Being::getCacheEntry(const BeingId id) { FOR_EACH (std::list<BeingCacheEntry*>::iterator, i, beingInfoCache) { @@ -3323,7 +3323,7 @@ void Being::addEffect(const std::string &name) paths.getStringValue("sprites") + name); } -void Being::addPet(const int id) +void Being::addPet(const BeingId id) { if (!actorManager || !config.getBoolValue("usepets")) return; @@ -3345,11 +3345,11 @@ void Being::addPet(const int id) int dstY = mY; being->fixPetSpawnPos(dstX, dstY); being->setTileCoords(dstX, dstY); - petHandler->spawn(this, being->mId, dstX, dstY); + //petHandler->spawn(this, being->mId, dstX, dstY); } } -Being *Being::findChildPet(const int id) +Being *Being::findChildPet(const BeingId id) { FOR_EACH (std::vector<Being*>::iterator, it, mPets) { @@ -3360,7 +3360,7 @@ Being *Being::findChildPet(const int id) return nullptr; } -void Being::removePet(const int id) +void Being::removePet(const BeingId id) { if (!actorManager) return; @@ -3406,8 +3406,8 @@ void Being::updatePets() if (!id) continue; const ItemInfo &info = ItemDB::get(id); - const int pet = info.getPet(); - if (pet) + const BeingId pet = fromInt(info.getPet(), BeingId); + if (pet != BeingId_zero) addPet(pet); } } @@ -3495,8 +3495,10 @@ void Being::fixPetSpawnPos(int &dstX, int &dstY) const } } -void Being::playSfx(const SoundInfo &sound, Being *const being, - const bool main, const int x, const int y) const +void Being::playSfx(const SoundInfo &sound, + Being *const being, + const bool main, + const int x, const int y) const { BLOCK_START("Being::playSfx") diff --git a/src/being/being.h b/src/being/being.h index 03a69b986..1b7db882a 100644 --- a/src/being/being.h +++ b/src/being/being.h @@ -105,7 +105,7 @@ class Being notfinal : public ActorSprite, * @param subtype partly determines the type of the being * @param map the map the being is on */ - Being(const int id, + Being(const BeingId id, const ActorType::Type type, const uint16_t subtype, Map *const map); @@ -571,7 +571,7 @@ class Being notfinal : public ActorSprite, static void reReadConfig(); - static BeingCacheEntry* getCacheEntry(const int id) A_WARN_UNUSED; + static BeingCacheEntry* getCacheEntry(const BeingId id) A_WARN_UNUSED; void addToCache() const; @@ -812,9 +812,9 @@ class Being notfinal : public ActorSprite, void addEffect(const std::string &name); - void addPet(const int id); + void addPet(const BeingId id); - void removePet(const int id); + void removePet(const BeingId id); void updatePets(); @@ -836,10 +836,12 @@ class Being notfinal : public ActorSprite, void removeAllPets(); - Being *findChildPet(const int id); + Being *findChildPet(const BeingId id); - void playSfx(const SoundInfo &sound, Being *const being, - const bool main, const int x, const int y) const; + void playSfx(const SoundInfo &sound, + Being *const being, + const bool main, + const int x, const int y) const; uint16_t getLook() const { return mLook; } diff --git a/src/being/beingcacheentry.h b/src/being/beingcacheentry.h index 388e9a993..59b0054fe 100644 --- a/src/being/beingcacheentry.h +++ b/src/being/beingcacheentry.h @@ -21,6 +21,8 @@ #ifndef BEING_BEINGCACHEENTRY_H #define BEING_BEINGCACHEENTRY_H +#include "enums/simpletypes/beingid.h" + #include "localconsts.h" #include <string> @@ -28,7 +30,7 @@ class BeingCacheEntry final { public: - explicit BeingCacheEntry(const int id) : + explicit BeingCacheEntry(const BeingId id) : mName(), mPartyName(), mGuildName(), @@ -44,7 +46,7 @@ class BeingCacheEntry final A_DELETE_COPY(BeingCacheEntry) - int getId() const + BeingId getId() const { return mId; } /** @@ -113,11 +115,11 @@ class BeingCacheEntry final { mFlags = flags; } protected: - std::string mName; /**< Name of character */ + std::string mName; /**< Name of character */ std::string mPartyName; std::string mGuildName; std::string mIp; - int mId; /**< Unique sprite id */ + BeingId mId; /**< Unique sprite id */ int mLevel; unsigned int mPvpRank; int mTime; diff --git a/src/being/homunculusinfo.h b/src/being/homunculusinfo.h index 6cf4232ba..ae1c01e84 100644 --- a/src/being/homunculusinfo.h +++ b/src/being/homunculusinfo.h @@ -21,6 +21,8 @@ #ifndef BEING_HOMUNCULUSINFO_H #define BEING_HOMUNCULUSINFO_H +#include "enums/simpletypes/beingid.h" + #include <string> #include "localconsts.h" @@ -29,7 +31,7 @@ struct HomunculusInfo final { HomunculusInfo() : name(), - id(0), + id(BeingId_zero), level(0), range(0), hungry(0), @@ -40,7 +42,7 @@ struct HomunculusInfo final A_DELETE_COPY(HomunculusInfo) std::string name; - int id; + BeingId id; int level; int range; int hungry; diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index efb483f6a..2bc2d928b 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -111,7 +111,8 @@ extern int weightNoticeTime; extern MiniStatusWindow *miniStatusWindow; extern SkillDialog *skillDialog; -LocalPlayer::LocalPlayer(const int id, const uint16_t subtype) : +LocalPlayer::LocalPlayer(const BeingId id, + const uint16_t subtype) : Being(id, ActorType::Player, subtype, nullptr), AttributeListener(), PlayerDeathListener(), @@ -139,7 +140,7 @@ LocalPlayer::LocalPlayer(const int id, const uint16_t subtype) : mActivityTime(0), mNavigateX(0), mNavigateY(0), - mNavigateId(0), + mNavigateId(BeingId_zero), mCrossX(0), mCrossY(0), mOldX(0), @@ -780,7 +781,7 @@ void LocalPlayer::attack(Being *const target, const bool keep, if (!dontChangeEquipment) changeEquipmentBeforeAttack(target); - const int targetId = target->getId(); + const BeingId targetId = target->getId(); playerHandler->attack(targetId, mServerAttack); #ifdef EATHENA_SUPPORT PlayerInfo::updateAttackAi(targetId, mServerAttack); @@ -813,13 +814,15 @@ void LocalPlayer::untarget() setTarget(nullptr); } -void LocalPlayer::pickedUp(const ItemInfo &itemInfo, const int amount, - const unsigned char color, const int floorItemId, +void LocalPlayer::pickedUp(const ItemInfo &itemInfo, + const int amount, + const unsigned char color, + const BeingId floorItemId, const Pickup::Type fail) { if (fail != Pickup::OKAY) { - if (actorManager && floorItemId) + if (actorManager && floorItemId != BeingId_zero) { FloorItem *const item = actorManager->findItem(floorItemId); if (item) @@ -1942,7 +1945,7 @@ bool LocalPlayer::navigateTo(const int x, const int y) mOldTileY = mY; mNavigateX = x; mNavigateY = y; - mNavigateId = 0; + mNavigateId = BeingId_zero; mNavigatePath = mMap->findPath( static_cast<int>(playerPos.x - mapTileSize / 2) / mapTileSize, @@ -1966,7 +1969,7 @@ void LocalPlayer::navigateClean() mOldTileY = 0; mNavigateX = 0; mNavigateY = 0; - mNavigateId = 0; + mNavigateId = BeingId_zero; mNavigatePath.clear(); @@ -2024,7 +2027,7 @@ void LocalPlayer::updateCoords() / mapTileSize; const int y = static_cast<int>(playerPos.y - mapTileSize) / mapTileSize; - if (mNavigateId) + if (mNavigateId != BeingId_zero) { if (!actorManager) { diff --git a/src/being/localplayer.h b/src/being/localplayer.h index 727ce5d6b..0d890c985 100644 --- a/src/being/localplayer.h +++ b/src/being/localplayer.h @@ -57,7 +57,7 @@ class LocalPlayer final : public Being, /** * Constructor. */ - explicit LocalPlayer(const int id = 65535, + explicit LocalPlayer(const BeingId id, const uint16_t subtype = 0U); A_DELETE_COPY(LocalPlayer) @@ -176,8 +176,10 @@ class LocalPlayer final : public Being, /** * Shows item pickup notifications. */ - void pickedUp(const ItemInfo &itemInfo, const int amount, - const unsigned char color, const int floorItemId, + void pickedUp(const ItemInfo &itemInfo, + const int amount, + const unsigned char color, + const BeingId floorItemId, const Pickup::Type fail); int getLevel() const override final A_WARN_UNUSED; @@ -467,7 +469,7 @@ class LocalPlayer final : public Being, int mActivityTime; int mNavigateX; int mNavigateY; - int mNavigateId; + BeingId mNavigateId; int mCrossX; int mCrossY; int mOldX; diff --git a/src/being/mercenaryinfo.h b/src/being/mercenaryinfo.h index 8e63afdc2..ea55854de 100644 --- a/src/being/mercenaryinfo.h +++ b/src/being/mercenaryinfo.h @@ -21,6 +21,7 @@ #ifndef BEING_MERCENARYINFO_H #define BEING_MERCENARYINFO_H +#include "enums/simpletypes/beingid.h" #include <string> #include "localconsts.h" @@ -29,7 +30,7 @@ struct MercenaryInfo final { MercenaryInfo() : name(), - id(0), + id(BeingId_zero), level(0), range(0) { } @@ -37,7 +38,7 @@ struct MercenaryInfo final A_DELETE_COPY(MercenaryInfo) std::string name; - int id; + BeingId id; int level; int range; }; diff --git a/src/being/petinfo.h b/src/being/petinfo.h index e67ae4139..fc7bcba84 100644 --- a/src/being/petinfo.h +++ b/src/being/petinfo.h @@ -21,6 +21,8 @@ #ifndef BEING_PETINFO_H #define BEING_PETINFO_H +#include "enums/simpletypes/beingid.h" + #include <string> #include "localconsts.h" @@ -29,7 +31,7 @@ struct PetInfo final { PetInfo() : name(), - id(0), + id(BeingId_zero), level(0), hungry(0), intimacy(0), @@ -42,7 +44,7 @@ struct PetInfo final A_DELETE_COPY(PetInfo) std::string name; - int id; + BeingId id; int level; int hungry; int intimacy; diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp index 576d6575d..f11b6fe82 100644 --- a/src/being/playerinfo.cpp +++ b/src/being/playerinfo.cpp @@ -62,7 +62,7 @@ PetInfo *mPet = nullptr; std::string mRoomName; #endif Equipment *mEquipment = nullptr; -int mPetBeingId = 0; +BeingId mPetBeingId = BeingId_zero; GuildPositionFlags::Type mGuildPositionFlags = GuildPositionFlags::None; Trading mTrading = Trading_false; @@ -399,7 +399,7 @@ void deinit() #ifdef EATHENA_SUPPORT delete2(mMercenary); #endif - mPetBeingId = 0; + mPetBeingId = BeingId_zero; } void loadData() @@ -412,7 +412,7 @@ void loadData() void clear() { mData.mSkills.clear(); - mPetBeingId = 0; + mPetBeingId = BeingId_zero; } bool isTalking() @@ -515,7 +515,7 @@ void setPetBeing(Being *const being) if (being) mPetBeingId = being->getId(); else - mPetBeingId = 0; + mPetBeingId = BeingId_zero; if (!being || !mPet) return; being->setName(mPet->name); @@ -528,7 +528,7 @@ PetInfo *getPet() return mPet; } -int getPetBeingId() +BeingId getPetBeingId() { return mPetBeingId; } @@ -553,14 +553,14 @@ HomunculusInfo *getHomunculus() return mHomunculus; } -int getHomunculusId() +BeingId getHomunculusId() { - return mHomunculus ? mHomunculus->id : 0; + return mHomunculus ? mHomunculus->id : BeingId_zero; } -int getMercenaryId() +BeingId getMercenaryId() { - return mMercenary ? mMercenary->id : 0; + return mMercenary ? mMercenary->id : BeingId_zero; } void updateMoveAI() @@ -571,7 +571,8 @@ void updateMoveAI() homunculusHandler->moveToMaster(); } -void updateAttackAi(const int targetId, const Keep keep) +void updateAttackAi(const BeingId targetId, + const Keep keep) { if (mMercenary) mercenaryHandler->attack(targetId, keep); diff --git a/src/being/playerinfo.h b/src/being/playerinfo.h index 00421918b..ee963a5eb 100644 --- a/src/being/playerinfo.h +++ b/src/being/playerinfo.h @@ -27,6 +27,7 @@ #include "enums/guildpositionflags.h" #include "enums/state.h" +#include "enums/simpletypes/beingid.h" #include "enums/simpletypes/keep.h" #include "enums/simpletypes/notify.h" #include "enums/simpletypes/sfx.h" @@ -261,7 +262,7 @@ namespace PlayerInfo void setPetBeing(Being *const being); - int getPetBeingId(); + BeingId getPetBeingId(); HomunculusInfo *getHomunculus(); @@ -269,13 +270,14 @@ namespace PlayerInfo void setHomunculusBeing(Being *const being); - int getHomunculusId(); + BeingId getHomunculusId(); - int getMercenaryId(); + BeingId getMercenaryId(); void updateMoveAI(); - void updateAttackAi(const int targetId, const Keep keep); + void updateAttackAi(const BeingId targetId, + const Keep keep); std::string getRoomName(); diff --git a/src/enums/simpletypes/beingid.h b/src/enums/simpletypes/beingid.h new file mode 100644 index 000000000..dddd83932 --- /dev/null +++ b/src/enums/simpletypes/beingid.h @@ -0,0 +1,34 @@ +/* + * The ManaPlus Client + * Copyright (C) 2015 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 ENUMS_SIMPLETYPES_BEINGID_H +#define ENUMS_SIMPLETYPES_BEINGID_H + +#include "enums/simpletypes/intdefines.h" + +defIntEnum(BeingId, int); + +#ifdef ADVGCC +const BeingId BeingId_negOne = static_cast<BeingId>(-1); +#else +const BeingId BeingId_negOne = -1; +#endif + +#endif // ENUMS_SIMPLETYPES_BEINGID_H diff --git a/src/enums/simpletypes/intdefines.h b/src/enums/simpletypes/intdefines.h index 56e052ce3..765318cdc 100644 --- a/src/enums/simpletypes/intdefines.h +++ b/src/enums/simpletypes/intdefines.h @@ -29,13 +29,18 @@ enum class name : type \ { \ }; \ + const name name##_zero = static_cast<name>(0) + #define fromInt(val, name) static_cast<name>(val) +#define toInt(val, name) static_cast<name>(val) #else // ADVGCC #define defIntEnum(name, type) \ - typedef type name + typedef type name; \ + const name name##_zero = 0 #define fromInt(val, name) (val) +#define toInt(val, name) (val) #endif // ADVGCC diff --git a/src/flooritem.cpp b/src/flooritem.cpp index 0de19f886..664beecf8 100644 --- a/src/flooritem.cpp +++ b/src/flooritem.cpp @@ -43,8 +43,11 @@ extern volatile int cur_time; -FloorItem::FloorItem(const int id, const int itemId, const int x, const int y, - const int amount, const unsigned char color) : +FloorItem::FloorItem(const BeingId id, + const int itemId, + const int x, const int y, + const int amount, + const unsigned char color) : ActorSprite(id), mItemId(itemId), mX(x), diff --git a/src/flooritem.h b/src/flooritem.h index 8d062eafa..dbeffa8dd 100644 --- a/src/flooritem.h +++ b/src/flooritem.h @@ -23,6 +23,8 @@ #ifndef FLOORITEM_H #define FLOORITEM_H +#include "enums/simpletypes/beingid.h" + #include "being/actorsprite.h" #include "resources/cursor.h" @@ -45,8 +47,11 @@ class FloorItem final : public ActorSprite * @param amount the item amount * @param color the item color */ - FloorItem(const int id, const int itemId, const int x, const int y, - const int amount, const unsigned char color); + FloorItem(const BeingId id, + const int itemId, + const int x, const int y, + const int amount, + const unsigned char color); A_DELETE_COPY(FloorItem) diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index dd48da369..ee34d4ff7 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -98,8 +98,8 @@ PopupMenu::PopupMenu() : mBrowserBox(new BrowserBox(this, BrowserBox::AUTO_SIZE, true, "popupbrowserbox.xml")), mScrollArea(nullptr), - mBeingId(0), - mFloorItemId(0), + mBeingId(BeingId_zero), + mFloorItemId(BeingId_zero), mItem(nullptr), mItemId(0), mItemColor(1), @@ -389,7 +389,7 @@ bool PopupMenu::addBeingMenu() if (!being) return false; - BeingInfo *const info = NPCDB::get(being->getSubType()); + BeingInfo *const info = NPCDB::get(fromInt(being->getSubType(), BeingId)); if (!info) return false; @@ -456,7 +456,7 @@ void PopupMenu::showPlayerPopup(const std::string &nick) setMousePos(); mNick = nick; - mBeingId = 0; + mBeingId = BeingId_zero; mType = ActorType::Player; mBrowserBox->clearRows(); @@ -931,8 +931,8 @@ void PopupMenu::showChangePos(const int x, const int y) } else { - mBeingId = 0; - mFloorItemId = 0; + mBeingId = BeingId_zero; + mFloorItemId = BeingId_zero; mItem = nullptr; mMapItem = nullptr; mNick.clear(); @@ -1109,7 +1109,7 @@ void PopupMenu::handleLink(const std::string &link, if (chatWindow) chatWindow->copyToClipboard(mX, mY); } - else if (link == "npc clipboard" && mBeingId) + else if (link == "npc clipboard" && mBeingId != BeingId_zero) { NpcDialog::copyToClipboard(mBeingId, mX, mY); } @@ -1474,7 +1474,7 @@ void PopupMenu::handleLink(const std::string &link, { if (actorManager) { - mBeingId = atoi(link.substr(7).c_str()); + mBeingId = fromInt(atoi(link.substr(7).c_str()), BeingId); being = actorManager->findBeing(mBeingId); if (being) { @@ -1487,8 +1487,9 @@ void PopupMenu::handleLink(const std::string &link, { if (actorManager) { - const int id = atoi(link.substr(10).c_str()); - if (id) + const BeingId id = fromInt(atoi( + link.substr(10).c_str()), BeingId); + if (id != BeingId_zero) { const FloorItem *const item = actorManager->findItem(id); if (item) @@ -1548,8 +1549,8 @@ void PopupMenu::handleLink(const std::string &link, replaceAll(cmd, "'NAME'", mNick); replaceAll(cmd, "'X'", toString(mX)); replaceAll(cmd, "'Y'", toString(mY)); - replaceAll(cmd, "'BEINGID'", toString(mBeingId)); - replaceAll(cmd, "'FLOORID'", toString(mFloorItemId)); + replaceAll(cmd, "'BEINGID'", toString(toInt(mBeingId, int))); + replaceAll(cmd, "'FLOORID'", toString(toInt(mFloorItemId, int))); replaceAll(cmd, "'ITEMID'", toString(mItemId)); replaceAll(cmd, "'ITEMCOLOR'", toString(mItemColor)); replaceAll(cmd, "'BEINGTYPEID'", toString(static_cast<int>(mType))); @@ -1583,8 +1584,8 @@ void PopupMenu::handleLink(const std::string &link, setVisible(Visible_false); - mBeingId = 0; - mFloorItemId = 0; + mBeingId = BeingId_zero; + mFloorItemId = BeingId_zero; mItem = nullptr; mItemId = 0; mItemColor = 1; @@ -2188,7 +2189,8 @@ void PopupMenu::showWindowsPopup() showPopup(mX, mY); } -void PopupMenu::showNpcDialogPopup(const int npcId, const int x, const int y) +void PopupMenu::showNpcDialogPopup(const BeingId npcId, + const int x, const int y) { mBeingId = npcId; mX = x; @@ -2625,7 +2627,7 @@ void PopupMenu::showGMPopup() // TRANSLATORS: popup menu item // TRANSLATORS: revive player mBrowserBox->addRow("revive", _("Revive")); - if (mBeingId) + if (mBeingId != BeingId_zero) { // TRANSLATORS: popup menu item // TRANSLATORS: kick player diff --git a/src/gui/popups/popupmenu.h b/src/gui/popups/popupmenu.h index 5d6420662..e1f9b3ba7 100644 --- a/src/gui/popups/popupmenu.h +++ b/src/gui/popups/popupmenu.h @@ -25,6 +25,8 @@ #include "enums/inventorytype.h" +#include "enums/simpletypes/beingid.h" + #include "gui/widgets/linkhandler.h" #include "gui/widgets/popup.h" @@ -140,7 +142,8 @@ class PopupMenu final : public Popup, public LinkHandler void showWindowsPopup(); - void showNpcDialogPopup(const int npcId, const int x, const int y); + void showNpcDialogPopup(const BeingId npcId, + const int x, const int y); void showWindowPopup(Window *const window); @@ -198,8 +201,8 @@ class PopupMenu final : public Popup, public LinkHandler BrowserBox *mBrowserBox; ScrollArea *mScrollArea; - int mBeingId; - int mFloorItemId; + BeingId mBeingId; + BeingId mFloorItemId; Item *mItem; int mItemId; unsigned char mItemColor; diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 196ac5d1c..e0ffd732f 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -920,7 +920,7 @@ void Viewport::moveCamera(const int dx, const int dy) mCameraRelativeY += dy; } -void Viewport::moveCameraToActor(const int actorId, +void Viewport::moveCameraToActor(const BeingId actorId, const int x, const int y) { if (!localPlayer || !actorManager) diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 10a5b6643..e459afcae 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -25,6 +25,8 @@ #include "position.h" +#include "enums/simpletypes/beingid.h" + #include "gui/widgets/windowcontainer.h" #include "listeners/mouselistener.h" @@ -155,7 +157,7 @@ class Viewport final : public WindowContainer, void setCameraRelativeY(const int n) { mCameraRelativeY = n; } - void moveCameraToActor(const int actorId, + void moveCameraToActor(const BeingId actorId, const int x = 0, const int y = 0); diff --git a/src/gui/widgets/tabs/debugwindowtabs.cpp b/src/gui/widgets/tabs/debugwindowtabs.cpp index faccf9b2e..704f1a114 100644 --- a/src/gui/widgets/tabs/debugwindowtabs.cpp +++ b/src/gui/widgets/tabs/debugwindowtabs.cpp @@ -323,7 +323,7 @@ void TargetDebugTab::logic() mTargetIdLabel->setCaption(strprintf("%s %d", // TRANSLATORS: debug window label - _("Target Id:"), target->getId())); + _("Target Id:"), toInt(target->getId(), int))); mTargetTypeLabel->setCaption(strprintf("%s %d", // TRANSLATORS: debug window label _("Target type:"), target->getSubType())); diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index 63925ff28..a77eed240 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -179,7 +179,7 @@ BuyDialog::BuyDialog() : mSortDropDown(nullptr), mFilterTextField(new TextField(this, "", true, this, "namefilter", true)), mFilterLabel(nullptr), - mNpcId(Items), + mNpcId(fromInt(Items, BeingId)), mMoney(0), mAmountItems(0), mMaxItems(0), @@ -188,7 +188,7 @@ BuyDialog::BuyDialog() : init(); } -BuyDialog::BuyDialog(const int npcId) : +BuyDialog::BuyDialog(const BeingId npcId) : // TRANSLATORS: buy dialog name Window(_("Buy"), Modal_false, nullptr, "buy.xml"), ActionListener(), @@ -216,7 +216,7 @@ BuyDialog::BuyDialog(std::string nick) : Modal_false, this, "sort")), mFilterTextField(new TextField(this, "", true, this, "namefilter", true)), mFilterLabel(nullptr), - mNpcId(Nick), + mNpcId(fromInt(Nick, BeingId)), mMoney(0), mAmountItems(0), mMaxItems(0), @@ -271,7 +271,7 @@ void BuyDialog::init() // You may change this symbol if your language uses another. mDecreaseButton = new Button(this, _("-"), "dec", this); // TRANSLATORS: buy dialog button - mBuyButton = new Button(this, mNpcId == Items + mBuyButton = new Button(this, mNpcId == fromInt(Items, BeingId) ? _("Create") :_("Buy"), "buy", this); // TRANSLATORS: buy dialog button mQuitButton = new Button(this, _("Quit"), "quit", this); @@ -406,7 +406,7 @@ void BuyDialog::sort() void BuyDialog::close() { - switch (mNpcId) + switch (toInt(mNpcId, int)) { case Nick: case Items: @@ -488,15 +488,15 @@ void BuyDialog::action(const ActionEvent &event) else if (eventId == "buy" && mAmountItems > 0 && mAmountItems <= mMaxItems) { ShopItem *const item = mShopItems->at(selectedItem); - if (mNpcId == Items) + if (mNpcId == fromInt(Items, BeingId)) { adminHandler->createItems(item->getId(), mAmountItems, item->getColor()); } - else if (mNpcId != Nick) + else if (mNpcId != fromInt(Nick, BeingId)) { #ifdef EATHENA_SUPPORT - if (mNpcId == Market) + if (mNpcId == fromInt(Market, BeingId)) { marketHandler->buyItem(item->getId(), item->getType(), @@ -505,7 +505,7 @@ void BuyDialog::action(const ActionEvent &event) item->increaseQuantity(-mAmountItems); item->update(); } - else if (mNpcId == Cash) + else if (mNpcId == fromInt(Cash, BeingId)) { cashShopHandler->buyItem(item->getPrice(), item->getId(), @@ -523,7 +523,7 @@ void BuyDialog::action(const ActionEvent &event) updateSlider(selectedItem); } - else if (mNpcId == Nick) + else if (mNpcId == fromInt(Nick, BeingId)) { #ifdef EATHENA_SUPPORT if (serverFeatures->haveVending()) @@ -594,7 +594,7 @@ void BuyDialog::updateButtonsAndLabels() const int itemPrice = item->getPrice(); // Calculate how many the player can afford - if (mNpcId == Items) + if (mNpcId == fromInt(Items, BeingId)) mMaxItems = 100; else if (itemPrice) mMaxItems = mMoney / itemPrice; diff --git a/src/gui/windows/buydialog.h b/src/gui/windows/buydialog.h index 8dea72886..bef09083e 100644 --- a/src/gui/windows/buydialog.h +++ b/src/gui/windows/buydialog.h @@ -23,6 +23,7 @@ #ifndef GUI_WINDOWS_BUYDIALOG_H #define GUI_WINDOWS_BUYDIALOG_H +#include "enums/simpletypes/beingid.h" #include "enums/simpletypes/visible.h" #include "gui/widgets/window.h" @@ -64,7 +65,7 @@ class BuyDialog final : public Window, * * @see Window::Window */ - explicit BuyDialog(const int npcId); + explicit BuyDialog(const BeingId npcId); /** * Constructor. @@ -175,7 +176,7 @@ class BuyDialog final : public Window, TextField *mFilterTextField; Label *mFilterLabel; - int mNpcId; + BeingId mNpcId; int mMoney; int mAmountItems; int mMaxItems; diff --git a/src/gui/windows/buyingstoreselldialog.cpp b/src/gui/windows/buyingstoreselldialog.cpp index 29b24f638..f99251eb0 100644 --- a/src/gui/windows/buyingstoreselldialog.cpp +++ b/src/gui/windows/buyingstoreselldialog.cpp @@ -37,7 +37,7 @@ #include "debug.h" -BuyingStoreSellDialog::BuyingStoreSellDialog(const int accountId, +BuyingStoreSellDialog::BuyingStoreSellDialog(const BeingId accountId, const int storeId) : SellDialog(true), mAccountId(accountId), diff --git a/src/gui/windows/buyingstoreselldialog.h b/src/gui/windows/buyingstoreselldialog.h index 9fb40cba0..ce5c404e4 100644 --- a/src/gui/windows/buyingstoreselldialog.h +++ b/src/gui/windows/buyingstoreselldialog.h @@ -25,6 +25,8 @@ #ifdef EATHENA_SUPPORT +#include "enums/simpletypes/beingid.h" + #include "gui/widgets/selldialog.h" class Being; @@ -42,7 +44,7 @@ class BuyingStoreSellDialog final : public SellDialog * * @see Window::Window */ - BuyingStoreSellDialog(const int accountId, + BuyingStoreSellDialog(const BeingId accountId, const int storeId); A_DELETE_COPY(BuyingStoreSellDialog) @@ -50,7 +52,7 @@ class BuyingStoreSellDialog final : public SellDialog protected: void sellAction(const ActionEvent &event) override final; - int mAccountId; + BeingId mAccountId; int mStoreId; }; diff --git a/src/gui/windows/buyselldialog.cpp b/src/gui/windows/buyselldialog.cpp index 15d4165f3..bdd28b000 100644 --- a/src/gui/windows/buyselldialog.cpp +++ b/src/gui/windows/buyselldialog.cpp @@ -35,7 +35,7 @@ BuySellDialog::DialogList BuySellDialog::dialogInstances; -BuySellDialog::BuySellDialog(const int npcId) : +BuySellDialog::BuySellDialog(const BeingId npcId) : // TRANSLATORS: shop window name Window(_("Shop"), Modal_false, nullptr, "buysell.xml"), ActionListener(), @@ -50,7 +50,7 @@ BuySellDialog::BuySellDialog(const std::string &nick) : // TRANSLATORS: shop window name Window(_("Shop"), Modal_false, nullptr, "buysell.xml"), ActionListener(), - mNpcId(-1), + mNpcId(BeingId_negOne), mNick(nick), mBuyButton(nullptr) { @@ -128,14 +128,14 @@ void BuySellDialog::action(const ActionEvent &event) const std::string &eventId = event.getId(); if (eventId == "Buy") { - if (mNpcId != -1) + if (mNpcId != BeingId_negOne) npcHandler->buy(mNpcId); else buySellHandler->requestSellList(mNick); } else if (eventId == "Sell") { - if (mNpcId != -1) + if (mNpcId != BeingId_negOne) npcHandler->sell(mNpcId); else buySellHandler->requestBuyList(mNick); diff --git a/src/gui/windows/buyselldialog.h b/src/gui/windows/buyselldialog.h index 573435846..dc7435126 100644 --- a/src/gui/windows/buyselldialog.h +++ b/src/gui/windows/buyselldialog.h @@ -23,6 +23,7 @@ #ifndef GUI_WINDOWS_BUYSELLDIALOG_H #define GUI_WINDOWS_BUYSELLDIALOG_H +#include "enums/simpletypes/beingid.h" #include "enums/simpletypes/visible.h" #include "gui/widgets/window.h" @@ -46,7 +47,7 @@ class BuySellDialog final : public Window, * * @see Window::Window */ - explicit BuySellDialog(const int npcId); + explicit BuySellDialog(const BeingId npcId); explicit BuySellDialog(const std::string &nick); @@ -78,7 +79,7 @@ class BuySellDialog final : public Window, typedef std::list<BuySellDialog*> DialogList; static DialogList dialogInstances; - int mNpcId; + BeingId mNpcId; std::string mNick; Button *mBuyButton; }; diff --git a/src/gui/windows/charcreatedialog.cpp b/src/gui/windows/charcreatedialog.cpp index 6ada41158..917cc51fb 100644 --- a/src/gui/windows/charcreatedialog.cpp +++ b/src/gui/windows/charcreatedialog.cpp @@ -122,7 +122,9 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent, mCreateButton(new Button(this, _("Create"), "create", this)), // TRANSLATORS: char create dialog button mCancelButton(new Button(this, _("Cancel"), "cancel", this)), - mPlayer(new Being(0, ActorType::Player, static_cast<uint16_t>(0U), + mPlayer(new Being(BeingId_zero, + ActorType::Player, + static_cast<uint16_t>(0U), nullptr)), mPlayerBox(new PlayerBox(this, mPlayer, "charcreate_playerbox.xml", "charcreate_selectedplayerbox.xml")), diff --git a/src/gui/windows/charselectdialog.cpp b/src/gui/windows/charselectdialog.cpp index 5663ab387..bb4eae95e 100644 --- a/src/gui/windows/charselectdialog.cpp +++ b/src/gui/windows/charselectdialog.cpp @@ -634,7 +634,7 @@ void CharSelectDialog::updateState() } } -void CharSelectDialog::setName(const int id, const std::string &newName) +void CharSelectDialog::setName(const BeingId id, const std::string &newName) { for (unsigned int i = 0, sz = static_cast<unsigned int>( mCharacterEntries.size()); i < sz; ++i) diff --git a/src/gui/windows/charselectdialog.h b/src/gui/windows/charselectdialog.h index 9e9871c5a..53d41facb 100644 --- a/src/gui/windows/charselectdialog.h +++ b/src/gui/windows/charselectdialog.h @@ -89,7 +89,7 @@ class CharSelectDialog final : public Window, void postInit() override final; - void setName(const int id, const std::string &newName); + void setName(const BeingId id, const std::string &newName); private: void attemptCharacterDelete(const int index, diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index 2c7c27f57..c8ccd482e 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -81,7 +81,7 @@ NpcDialogs NpcDialog::mNpcDialogs; typedef std::vector<Image *>::iterator ImageVectorIter; -NpcDialog::NpcDialog(const int npcId) : +NpcDialog::NpcDialog(const BeingId npcId) : // TRANSLATORS: npc dialog name Window(_("NPC"), Modal_false, nullptr, "npc.xml"), ActionListener(), @@ -204,7 +204,8 @@ void NpcDialog::postInit() const Being *const being = actorManager->findBeing(mNpcId); if (being) { - showAvatar(NPCDB::getAvatarFor(being->getSubType())); + showAvatar(NPCDB::getAvatarFor(fromInt( + being->getSubType(), BeingId))); setCaption(being->getName()); } } @@ -861,13 +862,16 @@ void NpcDialog::restoreCamera() mCameraMode = -1; } -void NpcDialog::showAvatar(const uint16_t avatarId) +void NpcDialog::showAvatar(const BeingId avatarId) { - const bool needShow = (avatarId != 0); + const bool needShow = (avatarId != BeingId_zero); if (needShow) { delete mAvatarBeing; - mAvatarBeing = new Being(0, ActorType::Avatar, avatarId, nullptr); + mAvatarBeing = new Being(BeingId_zero, + ActorType::Avatar, + toInt(avatarId, uint16_t), + nullptr); mPlayerBox->setPlayer(mAvatarBeing); if (!mAvatarBeing->empty()) { @@ -973,7 +977,8 @@ void NpcDialog::mousePressed(MouseEvent &event) } } -void NpcDialog::copyToClipboard(const int npcId, const int x, const int y) +void NpcDialog::copyToClipboard(const BeingId npcId, + const int x, const int y) { NpcDialogs::iterator it = mNpcDialogs.find(npcId); if (it != mNpcDialogs.end()) diff --git a/src/gui/windows/npcdialog.h b/src/gui/windows/npcdialog.h index 0ed4096e8..378bbd5e9 100644 --- a/src/gui/windows/npcdialog.h +++ b/src/gui/windows/npcdialog.h @@ -23,6 +23,7 @@ #ifndef GUI_WINDOWS_NPCDIALOG_H #define GUI_WINDOWS_NPCDIALOG_H +#include "enums/simpletypes/beingid.h" #include "enums/simpletypes/visible.h" #include "gui/models/extendedlistmodel.h" @@ -44,7 +45,7 @@ class PlayerBox; class ScrollArea; class TextField; -typedef std::map<int, NpcDialog*> NpcDialogs; +typedef std::map<BeingId, NpcDialog*> NpcDialogs; /** * The npc dialog. @@ -62,7 +63,7 @@ class NpcDialog final : public Window, * * @see Window::Window */ - explicit NpcDialog(const int npcId); + explicit NpcDialog(const BeingId npcId); A_DELETE_COPY(NpcDialog) @@ -196,7 +197,7 @@ class NpcDialog final : public Window, void refocus(); - void showAvatar(const uint16_t avatarId); + void showAvatar(const BeingId avatarId); void setAvatarDirection(const uint8_t direction); @@ -211,7 +212,8 @@ class NpcDialog final : public Window, int isCloseState() const { return mActionState == NPC_ACTION_CLOSE; } - static void copyToClipboard(const int npcId, const int x, const int y); + static void copyToClipboard(const BeingId npcId, + const int x, const int y); static NpcDialogs mNpcDialogs; @@ -233,7 +235,7 @@ class NpcDialog final : public Window, void placeItemInputControls(); - int mNpcId; + BeingId mNpcId; int mDefaultInt; std::string mDefaultString; diff --git a/src/gui/windows/npcselldialog.cpp b/src/gui/windows/npcselldialog.cpp index 683593deb..c1fdbe259 100644 --- a/src/gui/windows/npcselldialog.cpp +++ b/src/gui/windows/npcselldialog.cpp @@ -41,7 +41,7 @@ #include "debug.h" -NpcSellDialog::NpcSellDialog(const int npcId) : +NpcSellDialog::NpcSellDialog(const BeingId npcId) : SellDialog(true), mNpcId(npcId) { diff --git a/src/gui/windows/npcselldialog.h b/src/gui/windows/npcselldialog.h index 1932ddf42..af611f8f1 100644 --- a/src/gui/windows/npcselldialog.h +++ b/src/gui/windows/npcselldialog.h @@ -23,6 +23,8 @@ #ifndef GUI_WINDOWS_NPCSELLDIALOG_H #define GUI_WINDOWS_NPCSELLDIALOG_H +#include "enums/simpletypes/beingid.h" + #include "gui/widgets/selldialog.h" /** @@ -38,7 +40,7 @@ class NpcSellDialog final : public SellDialog * * @see Window::Window */ - explicit NpcSellDialog(const int npcId); + explicit NpcSellDialog(const BeingId npcId); A_DELETE_COPY(NpcSellDialog) @@ -47,7 +49,7 @@ class NpcSellDialog final : public SellDialog protected: void sellAction(const ActionEvent &event) override final; - int mNpcId; + BeingId mNpcId; }; #endif // GUI_WINDOWS_NPCSELLDIALOG_H diff --git a/src/guild.cpp b/src/guild.cpp index fae23eed5..9dd83bb40 100644 --- a/src/guild.cpp +++ b/src/guild.cpp @@ -60,8 +60,10 @@ namespace } guildSorter; } // namespace -GuildMember::GuildMember(Guild *const guild, const int accountId, - const int charId, const std::string &name) : +GuildMember::GuildMember(Guild *const guild, + const BeingId accountId, + const int charId, + const std::string &name) : Avatar(name), mGuild(guild), mPos(0) @@ -104,7 +106,8 @@ Guild::~Guild() clearMembers(); } -GuildMember *Guild::addMember(const int accountId, const int charId, +GuildMember *Guild::addMember(const BeingId accountId, + const int charId, const std::string &name) { GuildMember *m = getMember(accountId, charId); @@ -131,7 +134,7 @@ GuildMember *Guild::addMember(const std::string &name) return m; } -GuildMember *Guild::getMember(const int id) const +GuildMember *Guild::getMember(const BeingId id) const { MemberList::const_iterator itr = mMembers.begin(); const MemberList::const_iterator itr_end = mMembers.end(); @@ -145,7 +148,8 @@ GuildMember *Guild::getMember(const int id) const return nullptr; } -GuildMember *Guild::getMember(const int accountId, const int charId) const +GuildMember *Guild::getMember(const BeingId accountId, + const int charId) const { MemberList::const_iterator itr = mMembers.begin(); const MemberList::const_iterator itr_end = mMembers.end(); @@ -194,7 +198,7 @@ void Guild::removeMember(const GuildMember *const member) } } -void Guild::removeMember(const int id) +void Guild::removeMember(const BeingId id) { bool deleted = true; while (deleted) @@ -294,7 +298,7 @@ bool Guild::isMember(const GuildMember *const member) const return false; } -bool Guild::isMember(const int id) const +bool Guild::isMember(const BeingId id) const { MemberList::const_iterator itr = mMembers.begin(); const MemberList::const_iterator itr_end = mMembers.end(); diff --git a/src/guild.h b/src/guild.h index 2ed9db5b2..02c2f8794 100644 --- a/src/guild.h +++ b/src/guild.h @@ -53,7 +53,9 @@ class GuildMember final : public Avatar protected: friend class Guild; - GuildMember(Guild *const guild, const int id, const int accountId, + GuildMember(Guild *const guild, + const BeingId accountId, + const int charId, const std::string &name); GuildMember(Guild *const guild, const std::string &name); @@ -78,7 +80,8 @@ class Guild final : public AvatarListModel /** * Adds member to the list. */ - GuildMember *addMember(const int accountId, const int charId, + GuildMember *addMember(const BeingId accountId, + const int charId, const std::string &name); /** @@ -91,14 +94,15 @@ class Guild final : public AvatarListModel * * @return the member with the given ID, or NULL if they don't exist. */ - GuildMember *getMember(const int id) const; + GuildMember *getMember(const BeingId id) const; /** * Find a member by account ID and char ID. * * @return the member with the given ID, or NULL if they don't exist. */ - GuildMember *getMember(const int accountId, const int charId) + GuildMember *getMember(const BeingId accountId, + const int charId) const A_WARN_UNUSED; /** @@ -130,7 +134,7 @@ class Guild final : public AvatarListModel /** * Removes a member from the guild. */ - void removeMember(const int id); + void removeMember(const BeingId id); /** * Removes a member from the guild. @@ -162,7 +166,7 @@ class Guild final : public AvatarListModel bool isMember(const GuildMember *const member) const A_WARN_UNUSED; - bool isMember(const int id) const A_WARN_UNUSED; + bool isMember(const BeingId id) const A_WARN_UNUSED; bool isMember(const std::string &name) const A_WARN_UNUSED; diff --git a/src/listeners/charrenamelistener.cpp b/src/listeners/charrenamelistener.cpp index 7a09a09a3..a170cb9f3 100644 --- a/src/listeners/charrenamelistener.cpp +++ b/src/listeners/charrenamelistener.cpp @@ -31,7 +31,7 @@ CharRenameListener charRenameListener; CharRenameListener::CharRenameListener() : ActionListener(), mDialog(nullptr), - mId(0) + mId(BeingId_zero) { } diff --git a/src/listeners/charrenamelistener.h b/src/listeners/charrenamelistener.h index e01af8c01..5dce0a544 100644 --- a/src/listeners/charrenamelistener.h +++ b/src/listeners/charrenamelistener.h @@ -21,6 +21,8 @@ #ifndef LISTENERS_CHARRENAMELISTENER_H #define LISTENERS_CHARRENAMELISTENER_H +#include "enums/simpletypes/beingid.h" + #include "listeners/actionlistener.h" #include "localconsts.h" @@ -36,7 +38,7 @@ class CharRenameListener final : public ActionListener void action(const ActionEvent &event) override final; - void setId(const int id) + void setId(const BeingId id) { mId = id; } void setDialog(EditDialog *const dialog) @@ -44,7 +46,7 @@ class CharRenameListener final : public ActionListener protected: EditDialog *mDialog; - int mId; + BeingId mId; }; extern CharRenameListener charRenameListener; diff --git a/src/net/adminhandler.h b/src/net/adminhandler.h index 70e683769..77f0508a8 100644 --- a/src/net/adminhandler.h +++ b/src/net/adminhandler.h @@ -23,10 +23,12 @@ #ifndef NET_ADMINHANDLER_H #define NET_ADMINHANDLER_H -#include "localconsts.h" +#include "enums/simpletypes/beingid.h" #include <string> +#include "localconsts.h" + class Being; namespace Net @@ -44,7 +46,7 @@ class AdminHandler notfinal virtual void hide(const bool hide) const = 0; - virtual void kick(const int playerId) const = 0; + virtual void kick(const BeingId playerId) const = 0; virtual void kickName(const std::string &name) const = 0; diff --git a/src/net/beinghandler.h b/src/net/beinghandler.h index af6b05b8b..a99b0377c 100644 --- a/src/net/beinghandler.h +++ b/src/net/beinghandler.h @@ -26,6 +26,8 @@ #include "enums/being/rank.h" +#include "enums/simpletypes/beingid.h" + #include "net/messagein.h" namespace Net @@ -39,7 +41,7 @@ class BeingHandler notfinal virtual void handleMessage(Net::MessageIn &msg) = 0; - virtual void requestNameById(const int id) const = 0; + virtual void requestNameById(const BeingId id) const = 0; virtual void undress(Being *const being) const = 0; diff --git a/src/net/charserverhandler.h b/src/net/charserverhandler.h index 445545436..925346594 100644 --- a/src/net/charserverhandler.h +++ b/src/net/charserverhandler.h @@ -65,7 +65,7 @@ class CharServerHandler notfinal virtual void deleteCharacter(Net::Character *const character, const std::string &email) = 0; - virtual void renameCharacter(const int id, + virtual void renameCharacter(const BeingId id, const std::string &newName) = 0; virtual void switchCharacter() const = 0; diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 51771fb30..ab32a3f84 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -43,16 +43,17 @@ namespace Ea { -int BeingHandler::mSpawnId = 0; +BeingId BeingHandler::mSpawnId = BeingId_zero; bool BeingHandler::mSync = false; BeingHandler::BeingHandler(const bool enableSync) { mSync = enableSync; - mSpawnId = 0; + mSpawnId = BeingId_zero; } -Being *BeingHandler::createBeing(const int id, const int16_t job) +Being *BeingHandler::createBeing(const BeingId id, + const int16_t job) { if (!actorManager) return nullptr; @@ -93,7 +94,7 @@ void BeingHandler::processBeingRemove(Net::MessageIn &msg) // A being should be removed or has died - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); Being *const dstBeing = actorManager->findBeing(id); if (!dstBeing) { @@ -140,9 +141,9 @@ void BeingHandler::processSkillDamage(Net::MessageIn &msg) const int id = msg.readInt16("skill id"); Being *const srcBeing = actorManager->findBeing( - msg.readInt32("src being id")); + msg.readBeingId("src being id")); Being *const dstBeing = actorManager->findBeing( - msg.readInt32("dst being id")); + msg.readBeingId("dst being id")); msg.readInt32("tick"); msg.readInt32("src speed"); msg.readInt32("dst speed"); @@ -167,9 +168,9 @@ void BeingHandler::processBeingAction(Net::MessageIn &msg) } Being *const srcBeing = actorManager->findBeing( - msg.readInt32("src being id")); + msg.readBeingId("src being id")); Being *const dstBeing = actorManager->findBeing( - msg.readInt32("dst being id")); + msg.readBeingId("dst being id")); msg.readInt32("tick"); const int srcSpeed = msg.readInt32("src speed"); @@ -253,7 +254,8 @@ void BeingHandler::processBeingEmotion(Net::MessageIn &msg) return; } - Being *const dstBeing = actorManager->findBeing(msg.readInt32("being id")); + Being *const dstBeing = actorManager->findBeing( + msg.readBeingId("being id")); if (!dstBeing) { BLOCK_END("BeingHandler::processBeingEmotion") @@ -283,7 +285,7 @@ void BeingHandler::processNameResponse(Net::MessageIn &msg) return; } - const int beingId = msg.readInt32("being id"); + const BeingId beingId = msg.readBeingId("being id"); Being *const dstBeing = actorManager->findBeing(beingId); if (dstBeing) @@ -344,7 +346,7 @@ void BeingHandler::processPlayerStop(Net::MessageIn &msg) return; } - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); if (mSync || id != localPlayer->getId()) { @@ -409,7 +411,7 @@ void BeingHandler::processPvpMapMode(Net::MessageIn &msg) void BeingHandler::processPvpSet(Net::MessageIn &msg) { BLOCK_START("BeingHandler::processPvpSet") - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); const int rank = msg.readInt32("rank"); msg.readInt32("num"); if (actorManager) @@ -431,7 +433,7 @@ void BeingHandler::processNameResponse2(Net::MessageIn &msg) } const int len = msg.readInt16("len"); - const int beingId = msg.readInt32("account ic"); + const BeingId beingId = msg.readBeingId("account ic"); const std::string str = msg.readString(len - 8, "name"); Being *const dstBeing = actorManager->findBeing(beingId); if (dstBeing) @@ -481,7 +483,7 @@ void BeingHandler::processBeingMove3(Net::MessageIn &msg) const int len = msg.readInt16("len") - 14; Being *const dstBeing = actorManager->findBeing( - msg.readInt32("being id")); + msg.readBeingId("being id")); if (!dstBeing) { BLOCK_END("BeingHandler::processBeingMove3") diff --git a/src/net/ea/beinghandler.h b/src/net/ea/beinghandler.h index ca575e506..632381fb3 100644 --- a/src/net/ea/beinghandler.h +++ b/src/net/ea/beinghandler.h @@ -36,7 +36,7 @@ class BeingHandler notfinal : public Net::BeingHandler protected: explicit BeingHandler(const bool enableSync); - static Being *createBeing(const int id, + static Being *createBeing(const BeingId id, const int16_t job) A_WARN_UNUSED; static void setSprite(Being *const being, const unsigned int slot, @@ -71,7 +71,7 @@ class BeingHandler notfinal : public Net::BeingHandler static void processBeingMove3(Net::MessageIn &msg); // Should we honor server "Stop Walking" packets - static int mSpawnId; + static BeingId mSpawnId; static bool mSync; }; diff --git a/src/net/ea/buysellhandler.cpp b/src/net/ea/buysellhandler.cpp index e0f686cad..0e939c217 100644 --- a/src/net/ea/buysellhandler.cpp +++ b/src/net/ea/buysellhandler.cpp @@ -42,12 +42,12 @@ namespace Ea { -int BuySellHandler::mNpcId = 0; +BeingId BuySellHandler::mNpcId = BeingId_zero; BuyDialog *BuySellHandler::mBuyDialog = nullptr; BuySellHandler::BuySellHandler() { - mNpcId = 0; + mNpcId = BeingId_zero; mBuyDialog = nullptr; } @@ -55,7 +55,7 @@ void BuySellHandler::processNpcBuySellChoice(Net::MessageIn &msg) { if (!BuySellDialog::isActive()) { - mNpcId = msg.readInt32("npc id"); + mNpcId = msg.readBeingId("npc id"); BuySellDialog *const dialog = new BuySellDialog(mNpcId); dialog->postInit(); } diff --git a/src/net/ea/buysellhandler.h b/src/net/ea/buysellhandler.h index e972b1208..1667332bb 100644 --- a/src/net/ea/buysellhandler.h +++ b/src/net/ea/buysellhandler.h @@ -23,6 +23,8 @@ #ifndef NET_EA_BUYSELLHANDLER_H #define NET_EA_BUYSELLHANDLER_H +#include "enums/simpletypes/beingid.h" + #include "net/buysellhandler.h" class BuyDialog; @@ -44,7 +46,7 @@ class BuySellHandler notfinal : public Net::BuySellHandler static void processNpcBuyResponse(Net::MessageIn &msg); - static int mNpcId; + static BeingId mNpcId; static BuyDialog *mBuyDialog; }; diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp index a08b2b9e6..554276d17 100644 --- a/src/net/ea/chathandler.cpp +++ b/src/net/ea/chathandler.cpp @@ -148,7 +148,7 @@ void ChatHandler::processMVPEffect(Net::MessageIn &msg) { BLOCK_START("ChatHandler::processMVPEffect") // Display MVP player - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); if (localChatTab && actorManager && config.getBoolValue("showMVP")) { const Being *const being = actorManager->findBeing(id); diff --git a/src/net/ea/gamehandler.cpp b/src/net/ea/gamehandler.cpp index 31c487921..583ef3409 100644 --- a/src/net/ea/gamehandler.cpp +++ b/src/net/ea/gamehandler.cpp @@ -42,13 +42,13 @@ namespace Ea { std::string GameHandler::mMap; -int GameHandler::mCharID = 0; +BeingId GameHandler::mCharID = BeingId_zero; GameHandler::GameHandler() : Net::GameHandler() { mMap.clear(); - mCharID = 0; + mCharID = BeingId_zero; } void GameHandler::who() const @@ -92,7 +92,7 @@ void GameHandler::processMapQuitResponse(Net::MessageIn &msg) void GameHandler::clear() { mMap.clear(); - mCharID = 0; + mCharID = BeingId_zero; } void GameHandler::initEngines() const diff --git a/src/net/ea/gamehandler.h b/src/net/ea/gamehandler.h index 4ecc85692..7ff3a5ca9 100644 --- a/src/net/ea/gamehandler.h +++ b/src/net/ea/gamehandler.h @@ -23,6 +23,8 @@ #ifndef NET_EA_GAMEHANDLER_H #define NET_EA_GAMEHANDLER_H +#include "enums/simpletypes/beingid.h" + #include "net/gamehandler.h" namespace Net @@ -62,7 +64,7 @@ class GameHandler notfinal : public Net::GameHandler protected: static std::string mMap; - static int mCharID; // < Saved for map-server switching + static BeingId mCharID; // < Saved for map-server switching }; } // namespace Ea diff --git a/src/net/ea/guildhandler.cpp b/src/net/ea/guildhandler.cpp index 13317699b..96956b2d9 100644 --- a/src/net/ea/guildhandler.cpp +++ b/src/net/ea/guildhandler.cpp @@ -186,7 +186,7 @@ void GuildHandler::processGuildMemberList(Net::MessageIn &msg) int totalNum = 0; for (int i = 0; i < count; i++) { - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const int charId = msg.readInt32("char id"); msg.readInt16("hair"); msg.readInt16("hair color"); @@ -290,7 +290,7 @@ void GuildHandler::processGuildPositionChanged(Net::MessageIn &msg) void GuildHandler::processGuildMemberPosChange(Net::MessageIn &msg) { msg.readInt16("len"); - const int accountId = msg.readInt32("account id"); + const BeingId accountId = msg.readBeingId("account id"); const int charId = msg.readInt32("char id"); const int pos = msg.readInt32("position"); if (taGuild) diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h index 26d74d56a..6050baaff 100644 --- a/src/net/ea/inventoryhandler.h +++ b/src/net/ea/inventoryhandler.h @@ -41,7 +41,7 @@ namespace Ea { typedef std::vector<InventoryItem> InventoryItems; -typedef std::queue<int> PickupQueue; +typedef std::queue<BeingId> PickupQueue; class InventoryHandler notfinal : public Net::InventoryHandler { @@ -65,7 +65,7 @@ class InventoryHandler notfinal : public Net::InventoryHandler size_t getSize(const int type) const override final A_WARN_UNUSED; - void pushPickup(const int floorId) + void pushPickup(const BeingId floorId) { mSentPickups.push(floorId); } static int getSlot(const int eAthenaSlot) A_WARN_UNUSED; diff --git a/src/net/ea/itemhandler.cpp b/src/net/ea/itemhandler.cpp index a4c1a164b..2c297f69f 100644 --- a/src/net/ea/itemhandler.cpp +++ b/src/net/ea/itemhandler.cpp @@ -41,7 +41,7 @@ ItemHandler::~ItemHandler() void ItemHandler::processItemVisible(Net::MessageIn &msg) { - const int id = msg.readInt32("item object id"); + const BeingId id = msg.readBeingId("item object id"); const int itemId = msg.readInt16("item id"); const uint8_t identify = msg.readUInt8("identify"); const int x = msg.readInt16("x"); @@ -62,7 +62,7 @@ void ItemHandler::processItemRemove(Net::MessageIn &msg) if (actorManager) { if (FloorItem *const item = actorManager - ->findItem(msg.readInt32("floor item id"))) + ->findItem(msg.readBeingId("floor item id"))) { actorManager->destroy(item); } diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index 8b8077cde..396eb1480 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -163,7 +163,7 @@ void LoginHandler::processLoginData(Net::MessageIn &msg) const int worldCount = (msg.getLength() - 47) / 32; mToken.session_ID1 = msg.readInt32("session id1"); - mToken.account_ID = msg.readInt32("accound id"); + mToken.account_ID = msg.readBeingId("accound id"); mToken.session_ID2 = msg.readInt32("session id2"); msg.readInt32("old ip"); loginData.lastLogin = msg.readString(24, "last login"); diff --git a/src/net/ea/npchandler.cpp b/src/net/ea/npchandler.cpp index a88025b7f..bfa3c3f81 100644 --- a/src/net/ea/npchandler.cpp +++ b/src/net/ea/npchandler.cpp @@ -104,7 +104,7 @@ void NpcHandler::processNpcIntInput(Net::MessageIn &msg) void NpcHandler::processNpcStrInput(Net::MessageIn &msg) { // Request for a string - int npcId = npcHandler->getNpc(msg); + BeingId npcId = npcHandler->getNpc(msg); if (mRequestLang) { mRequestLang = false; @@ -118,11 +118,11 @@ void NpcHandler::processNpcStrInput(Net::MessageIn &msg) void NpcHandler::processNpcCommand(Net::MessageIn &msg) { - const int npcId = npcHandler->getNpc(msg); + const BeingId npcId = npcHandler->getNpc(msg); mRequestLang = false; const int cmd = msg.readInt16("cmd"); - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("id"); const int x = msg.readInt16("x"); const int y = msg.readInt16("y"); switch (cmd) @@ -139,7 +139,7 @@ void NpcHandler::processNpcCommand(Net::MessageIn &msg) case 2: if (viewport) { - if (!id) + if (id == BeingId_zero) viewport->moveCameraToPosition(x, y); else viewport->moveCameraToActor(id, x, y); @@ -165,7 +165,7 @@ void NpcHandler::processNpcCommand(Net::MessageIn &msg) case 6: // show avatar if (mDialog) { - mDialog->showAvatar(static_cast<uint16_t>(id)); + mDialog->showAvatar(id); } break; case 7: // set avatar direction @@ -178,7 +178,7 @@ void NpcHandler::processNpcCommand(Net::MessageIn &msg) break; case 8: // set avatar action if (mDialog) - mDialog->setAvatarAction(id); + mDialog->setAvatarAction(toInt(id, int)); break; case 9: // clear npc dialog if (mDialog) @@ -186,7 +186,7 @@ void NpcHandler::processNpcCommand(Net::MessageIn &msg) break; case 10: // send selected item id { - int invSize = id; + int invSize = toInt(id, int); if (!invSize) invSize = 1; if (mDialog) diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp index f30a0a83f..1af9ba7ef 100644 --- a/src/net/ea/partyhandler.cpp +++ b/src/net/ea/partyhandler.cpp @@ -140,7 +140,7 @@ void PartyHandler::processPartySettingsContinue(Net::MessageIn &msg, void PartyHandler::processPartyLeave(Net::MessageIn &msg) { - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const std::string nick = msg.readString(24, "nick"); const int reason = msg.readUInt8("flag"); if (!localPlayer) @@ -224,7 +224,7 @@ void PartyHandler::processPartyLeave(Net::MessageIn &msg) void PartyHandler::processPartyUpdateCoords(Net::MessageIn &msg) { - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("account id"); PartyMember *m = nullptr; if (Ea::taParty) m = Ea::taParty->getMember(id); diff --git a/src/net/ea/token.h b/src/net/ea/token.h index 65368b6e2..a62136aee 100644 --- a/src/net/ea/token.h +++ b/src/net/ea/token.h @@ -20,6 +20,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "enums/simpletypes/beingid.h" #include "enums/being/gender.h" #ifndef NET_EA_TOKEN_H @@ -27,14 +28,14 @@ struct Token final { - int account_ID; + BeingId account_ID; int session_ID1; int session_ID2; Gender::Type sex; void clear() { - account_ID = 0; + account_ID = BeingId_zero; session_ID1 = 0; session_ID2 = 0; sex = Gender::UNSPECIFIED; diff --git a/src/net/eathena/adminhandler.cpp b/src/net/eathena/adminhandler.cpp index 75250d2b7..92e158a8e 100644 --- a/src/net/eathena/adminhandler.cpp +++ b/src/net/eathena/adminhandler.cpp @@ -95,10 +95,10 @@ void AdminHandler::hide(const bool h A_UNUSED) const outMsg.writeInt32(0, "unused"); } -void AdminHandler::kick(const int playerId) const +void AdminHandler::kick(const BeingId playerId) const { createOutPacket(CMSG_ADMIN_KICK); - outMsg.writeInt32(playerId, "account id"); + outMsg.writeBeingId(playerId, "account id"); } void AdminHandler::kickAll() const @@ -146,7 +146,7 @@ void AdminHandler::mute(const Being *const being, return; createOutPacket(CMSG_ADMIN_MUTE); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); outMsg.writeInt8(static_cast<int8_t>(type), "type"); outMsg.writeInt16(static_cast<int16_t>(limit), "value"); } @@ -163,7 +163,7 @@ void AdminHandler::requestLogin(const Being *const being) const return; createOutPacket(CMSG_ADMIN_ID_TO_LOGIN); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); } void AdminHandler::setTileType(const int x, const int y, @@ -181,13 +181,13 @@ void AdminHandler::unequipAll(const Being *const being) const return; createOutPacket(CMSG_ADMIN_UNEQUIP_ALL); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); } void AdminHandler::processAdminGetLoginAck(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readString(24, "login"); } diff --git a/src/net/eathena/adminhandler.h b/src/net/eathena/adminhandler.h index 7faf9b383..e1e76f75f 100644 --- a/src/net/eathena/adminhandler.h +++ b/src/net/eathena/adminhandler.h @@ -45,7 +45,7 @@ class AdminHandler final : public MessageHandler, public Ea::AdminHandler void hide(const bool h) const override final; - void kick(const int playerId) const override final; + void kick(const BeingId playerId) const override final; void kickAll() const override final; diff --git a/src/net/eathena/battlegroundhandler.cpp b/src/net/eathena/battlegroundhandler.cpp index 3444c9434..dd1f6bfe9 100644 --- a/src/net/eathena/battlegroundhandler.cpp +++ b/src/net/eathena/battlegroundhandler.cpp @@ -95,7 +95,7 @@ void BattleGroundHandler::handleMessage(Net::MessageIn &msg) void BattleGroundHandler::processBattleEmblem(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readString(24, "name"); msg.readInt16("camp"); } @@ -110,7 +110,7 @@ void BattleGroundHandler::processBattleUpdateScore(Net::MessageIn &msg) void BattleGroundHandler::processBattleUpdateCoords(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readString(24, "name"); msg.readInt16("class"); msg.readInt16("x"); diff --git a/src/net/eathena/beinghandler.cpp b/src/net/eathena/beinghandler.cpp index 29b7a2578..9bc79c407 100644 --- a/src/net/eathena/beinghandler.cpp +++ b/src/net/eathena/beinghandler.cpp @@ -142,10 +142,10 @@ BeingHandler::BeingHandler(const bool enableSync) : beingHandler = this; } -void BeingHandler::requestNameById(const int id) const +void BeingHandler::requestNameById(const BeingId id) const { createOutPacket(CMSG_NAME_REQUEST); - outMsg.writeInt32(id, "being id"); + outMsg.writeBeingId(id, "being id"); } void BeingHandler::handleMessage(Net::MessageIn &msg) @@ -414,7 +414,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) } Being *BeingHandler::createBeing2(Net::MessageIn &msg, - const int id, + const BeingId id, const int16_t job, const BeingType::BeingType beingType) { @@ -497,7 +497,7 @@ void BeingHandler::processBeingChangeLook2(Net::MessageIn &msg) return; Being *const dstBeing = actorManager->findBeing( - msg.readInt32("being id")); + msg.readBeingId("being id")); const uint8_t type = msg.readUInt8("type"); const int id = msg.readInt16("id1"); @@ -627,13 +627,13 @@ void BeingHandler::processBeingVisible(Net::MessageIn &msg) msg.readUInt8("object type")); // Information about a being in range - const int id = msg.readInt32("being id"); - int spawnId; + const BeingId id = msg.readBeingId("being id"); + BeingId spawnId; if (id == mSpawnId) spawnId = mSpawnId; else - spawnId = 0; - mSpawnId = 0; + spawnId = BeingId_zero; + mSpawnId = BeingId_zero; int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); @@ -673,7 +673,7 @@ void BeingHandler::processBeingVisible(Net::MessageIn &msg) if (dstBeing->getType() == ActorType::Player) dstBeing->setMoveTime(); - if (spawnId) + if (spawnId != BeingId_zero) { dstBeing->setAction(BeingAction::SPAWN, 0); } @@ -787,13 +787,13 @@ void BeingHandler::processBeingMove(Net::MessageIn &msg) msg.readUInt8("object type")); // Information about a being in range - const int id = msg.readInt32("being id"); - int spawnId; + const BeingId id = msg.readBeingId("being id"); + BeingId spawnId; if (id == mSpawnId) spawnId = mSpawnId; else - spawnId = 0; - mSpawnId = 0; + spawnId = BeingId_zero; + mSpawnId = BeingId_zero; int16_t speed = msg.readInt16("speed"); // if (visible) // { @@ -841,7 +841,7 @@ void BeingHandler::processBeingMove(Net::MessageIn &msg) if (dstBeing->getType() == ActorType::Player) dstBeing->setMoveTime(); - if (spawnId) + if (spawnId != BeingId_zero) dstBeing->setAction(BeingAction::SPAWN, 0); // Prevent division by 0 when calculating frame @@ -961,9 +961,9 @@ void BeingHandler::processBeingSpawn(Net::MessageIn &msg) msg.readUInt8("object type")); // Information about a being in range - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); mSpawnId = id; - const int spawnId = id; + const BeingId spawnId = id; int16_t speed = msg.readInt16("speed"); // if (visible) // { @@ -1011,10 +1011,8 @@ void BeingHandler::processBeingSpawn(Net::MessageIn &msg) if (dstBeing->getType() == ActorType::Player) dstBeing->setMoveTime(); - if (spawnId) - { + if (spawnId != BeingId_zero) dstBeing->setAction(BeingAction::SPAWN, 0); - } // Prevent division by 0 when calculating frame if (speed == 0) @@ -1138,8 +1136,8 @@ void BeingHandler::processSkillCasting(Net::MessageIn &msg) { // +++ need use other parameters - const int srcId = msg.readInt32("src id"); - const int dstId = msg.readInt32("dst id"); + const BeingId srcId = msg.readBeingId("src id"); + const BeingId dstId = msg.readBeingId("dst id"); const int dstX = msg.readInt16("dst x"); const int dstY = msg.readInt16("dst y"); const int skillId = msg.readInt16("skill id"); @@ -1150,12 +1148,12 @@ void BeingHandler::processSkillCasting(Net::MessageIn &msg) if (!effectManager) return; - if (srcId == 0) + if (srcId == BeingId_zero) { UNIMPLIMENTEDPACKET; return; } - else if (dstId != 0) + else if (dstId != BeingId_zero) { // being to being Being *const srcBeing = actorManager->findBeing(srcId); Being *const dstBeing = actorManager->findBeing(dstId); @@ -1179,7 +1177,7 @@ void BeingHandler::processBeingStatusChange(Net::MessageIn &msg) // Status change const uint16_t status = msg.readInt16("status"); - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); const Enable flag = fromBool( msg.readUInt8("flag: 0: stop, 1: start"), Enable); msg.readInt32("total"); @@ -1205,7 +1203,7 @@ void BeingHandler::processBeingStatusChange2(Net::MessageIn &msg) // Status change const uint16_t status = msg.readInt16("status"); - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); const Enable flag = fromBool( msg.readUInt8("flag: 0: stop, 1: start"), Enable); msg.readInt32("left"); @@ -1233,7 +1231,7 @@ void BeingHandler::processBeingMove2(Net::MessageIn &msg) * later versions of eAthena for both mobs and * players */ - Being *const dstBeing = actorManager->findBeing(msg.readInt32("being id")); + Being *const dstBeing = actorManager->findBeing(msg.readBeingId("being id")); uint16_t srcX, srcY, dstX, dstY; msg.readCoordinatePair(srcX, srcY, dstX, dstY, "move path"); @@ -1272,9 +1270,9 @@ void BeingHandler::processBeingAction2(Net::MessageIn &msg) } Being *const srcBeing = actorManager->findBeing( - msg.readInt32("src being id")); + msg.readBeingId("src being id")); Being *const dstBeing = actorManager->findBeing( - msg.readInt32("dst being id")); + msg.readBeingId("dst being id")); msg.readInt32("tick"); const int srcSpeed = msg.readInt32("src speed"); @@ -1356,7 +1354,7 @@ void BeingHandler::processBeingAction2(Net::MessageIn &msg) void BeingHandler::processMonsterHp(Net::MessageIn &msg) { Being *const dstBeing = actorManager->findBeing( - msg.readInt32("monster id")); + msg.readBeingId("monster id")); const int hp = msg.readInt32("hp"); const int maxHP = msg.readInt32("max hp"); if (dstBeing) @@ -1440,7 +1438,7 @@ void BeingHandler::processBeingChangeDirection(Net::MessageIn &msg) return; } - Being *const dstBeing = actorManager->findBeing(msg.readInt32("being id")); + Being *const dstBeing = actorManager->findBeing(msg.readBeingId("being id")); msg.readInt16("head direction"); @@ -1464,7 +1462,7 @@ void BeingHandler::processBeingSpecialEffect(Net::MessageIn &msg) if (!effectManager || !actorManager) return; - const int id = static_cast<uint32_t>(msg.readInt32("being id")); + const BeingId id = msg.readBeingId("being id"); Being *const being = actorManager->findBeing(id); if (!being) return; @@ -1487,7 +1485,7 @@ void BeingHandler::processBeingSpecialEffectNum(Net::MessageIn &msg) UNIMPLIMENTEDPACKET; // +++ need somhow show this effects. // type is not same with self/misc effect. - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readInt32("effect type"); msg.readInt32("num"); // effect variable } @@ -1539,7 +1537,7 @@ void BeingHandler::viewPlayerEquipment(const Being *const being) return; createOutPacket(CMSG_PLAYER_VIEW_EQUIPMENT); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); } void BeingHandler::processSkillGroundNoDamage(Net::MessageIn &msg) @@ -1577,7 +1575,7 @@ void BeingHandler::processPlaterStatusChange(Net::MessageIn &msg) } // Change in players' flags - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); Being *const dstBeing = actorManager->findBeing(id); if (!dstBeing) return; @@ -1600,7 +1598,7 @@ void BeingHandler::processPlaterStatusChange2(Net::MessageIn &msg) if (!actorManager) return; - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); Being *const dstBeing = actorManager->findBeing(id); if (!dstBeing) return; @@ -1618,7 +1616,7 @@ void BeingHandler::processPlaterStatusChange2(Net::MessageIn &msg) void BeingHandler::processPlaterStatusChangeNoTick(Net::MessageIn &msg) { const uint16_t status = msg.readInt16("index"); - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const Enable flag = fromBool(msg.readUInt8("state") ? true : false, Enable); @@ -1640,7 +1638,7 @@ void BeingHandler::processBeingResurrect(Net::MessageIn &msg) // A being changed mortality status - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); msg.readInt16("unused"); Being *const dstBeing = actorManager->findBeing(id); if (!dstBeing) @@ -1666,7 +1664,7 @@ void BeingHandler::processPlayerGuilPartyInfo(Net::MessageIn &msg) return; } - Being *const dstBeing = actorManager->findBeing(msg.readInt32("being id")); + Being *const dstBeing = actorManager->findBeing(msg.readBeingId("being id")); if (dstBeing) { @@ -1690,7 +1688,7 @@ void BeingHandler::processBeingFakeName(Net::MessageIn &msg) { const BeingType::BeingType type = static_cast<BeingType::BeingType>( msg.readUInt8("object type")); - const int id = msg.readInt32("npc id"); + const BeingId id = msg.readBeingId("npc id"); msg.skip(8, "unused"); const uint16_t job = msg.readInt16("class?"); // 111 msg.skip(30, "unused"); @@ -1709,7 +1707,7 @@ void BeingHandler::processBeingFakeName(Net::MessageIn &msg) void BeingHandler::processBeingStatUpdate1(Net::MessageIn &msg) { - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const int type = msg.readInt16("type"); const int value = msg.readInt32("value"); @@ -1734,7 +1732,7 @@ void BeingHandler::processBeingSelfEffect(Net::MessageIn &msg) return; } - const int id = static_cast<uint32_t>(msg.readInt32("being id")); + const BeingId id = msg.readBeingId("being id"); Being *const being = actorManager->findBeing(id); if (!being) { @@ -1755,7 +1753,7 @@ void BeingHandler::processMobInfo(Net::MessageIn &msg) if (len < 12) return; Being *const dstBeing = actorManager->findBeing( - msg.readInt32("monster id")); + msg.readBeingId("monster id")); const int attackRange = msg.readInt32("range"); if (dstBeing) dstBeing->setAttackRange(attackRange); @@ -1767,7 +1765,7 @@ void BeingHandler::processBeingAttrs(Net::MessageIn &msg) if (len < 12) return; Being *const dstBeing = actorManager->findBeing( - msg.readInt32("player id")); + msg.readBeingId("player id")); const int gmLevel = msg.readInt32("gm level"); if (dstBeing && gmLevel) { @@ -1802,7 +1800,7 @@ void BeingHandler::processClassChange(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("being id"); + msg.readBeingId("being id"); msg.readUInt8("type"); msg.readInt32("class"); } @@ -1811,7 +1809,7 @@ void BeingHandler::processSpiritBalls(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("being id"); + msg.readBeingId("being id"); msg.readInt16("spirits amount"); } @@ -1819,7 +1817,7 @@ void BeingHandler::processSpiritBallSingle(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("being id"); + msg.readBeingId("being id"); msg.readInt16("spirits amount"); } @@ -1836,7 +1834,7 @@ void BeingHandler::processComboDelay(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("being id"); + msg.readBeingId("being id"); msg.readInt32("wait"); } @@ -1844,14 +1842,14 @@ void BeingHandler::processWddingEffect(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("being id"); + msg.readBeingId("being id"); } void BeingHandler::processBeingSlide(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("being id"); + msg.readBeingId("being id"); msg.readInt16("x"); msg.readInt16("y"); } @@ -1891,7 +1889,7 @@ void BeingHandler::processBeingFont(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readInt16("font"); } @@ -1899,7 +1897,7 @@ void BeingHandler::processBeingMilleniumShield(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readInt16("shields"); msg.readInt16("unused"); } @@ -1908,7 +1906,7 @@ void BeingHandler::processBeingCharm(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readInt16("charm type"); msg.readInt16("charm count"); } diff --git a/src/net/eathena/beinghandler.h b/src/net/eathena/beinghandler.h index f6fb1df78..e60318314 100644 --- a/src/net/eathena/beinghandler.h +++ b/src/net/eathena/beinghandler.h @@ -40,7 +40,7 @@ class BeingHandler final : public MessageHandler, public Ea::BeingHandler void handleMessage(Net::MessageIn &msg) override final; - void requestNameById(const int id) const override final; + void requestNameById(const BeingId id) const override final; void undress(Being *const being) const override final; @@ -48,7 +48,7 @@ class BeingHandler final : public MessageHandler, public Ea::BeingHandler protected: static Being *createBeing2(Net::MessageIn &msg, - const int id, + const BeingId id, const int16_t job, const BeingType::BeingType beingType); diff --git a/src/net/eathena/buyingstorehandler.cpp b/src/net/eathena/buyingstorehandler.cpp index a68111dc1..baaee1aca 100644 --- a/src/net/eathena/buyingstorehandler.cpp +++ b/src/net/eathena/buyingstorehandler.cpp @@ -150,7 +150,7 @@ void BuyingStoreHandler::processBuyingStoreCreateFailed(Net::MessageIn &msg) void BuyingStoreHandler::processBuyingStoreOwnItems(Net::MessageIn &msg) { const int count = (msg.readInt16("len") - 12) / 9; - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readInt32("money limit"); for (int f = 0; f < count; f ++) { @@ -165,7 +165,7 @@ void BuyingStoreHandler::processBuyingStoreOwnItems(Net::MessageIn &msg) void BuyingStoreHandler::processBuyingStoreShowBoard(Net::MessageIn &msg) { - const int id = msg.readInt32("owner id"); + const BeingId id = msg.readBeingId("owner id"); const std::string shopName = msg.readString(80, "shop name"); Being *const dstBeing = actorManager->findBeing(id); if (dstBeing) @@ -174,7 +174,7 @@ void BuyingStoreHandler::processBuyingStoreShowBoard(Net::MessageIn &msg) void BuyingStoreHandler::processBuyingStoreHideBoard(Net::MessageIn &msg) { - const int id = msg.readInt32("owner id"); + const BeingId id = msg.readBeingId("owner id"); Being *const dstBeing = actorManager->findBeing(id); if (dstBeing) dstBeing->setBuyBoard(std::string()); @@ -188,7 +188,7 @@ void BuyingStoreHandler::processBuyingStoreHideBoard(Net::MessageIn &msg) void BuyingStoreHandler::processBuyingStoreItemsList(Net::MessageIn &msg) { const int count = (msg.readInt16("len") - 16) / 9; - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const int storeId = msg.readInt32("store id"); // +++ in future need use it too msg.readInt32("money limit"); @@ -321,7 +321,7 @@ void BuyingStoreHandler::open(const Being *const being) const if (!being) return; createOutPacket(CMSG_BUYINGSTORE_OPEN); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); } void BuyingStoreHandler::sell(const Being *const being, @@ -334,7 +334,7 @@ void BuyingStoreHandler::sell(const Being *const being, createOutPacket(CMSG_BUYINGSTORE_SELL); outMsg.writeInt16(18, "len"); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); outMsg.writeInt32(storeId, "store id"); outMsg.writeInt16(static_cast<int16_t>( item->getInvIndex() + INVENTORY_OFFSET), diff --git a/src/net/eathena/cashshophandler.cpp b/src/net/eathena/cashshophandler.cpp index 90eb1b2af..c2b872eca 100644 --- a/src/net/eathena/cashshophandler.cpp +++ b/src/net/eathena/cashshophandler.cpp @@ -95,7 +95,7 @@ void CashShopHandler::processCashShopOpen(Net::MessageIn &msg) { const int count = (msg.readInt16("len") - 12) / 11; - mBuyDialog = new BuyDialog(BuyDialog::Cash); + mBuyDialog = new BuyDialog(fromInt(BuyDialog::Cash, BeingId)); mBuyDialog->postInit(); mBuyDialog->setMoney(PlayerInfo::getAttribute(Attributes::MONEY)); diff --git a/src/net/eathena/charserverhandler.cpp b/src/net/eathena/charserverhandler.cpp index 0a634c80f..f94e3a34f 100644 --- a/src/net/eathena/charserverhandler.cpp +++ b/src/net/eathena/charserverhandler.cpp @@ -64,8 +64,8 @@ extern ServerInfo mapServer; std::string CharServerHandler::mNewName; uint32_t CharServerHandler::mPinSeed = 0; -uint32_t CharServerHandler::mPinAccountId = 0; -uint32_t CharServerHandler::mRenameId = 0; +BeingId CharServerHandler::mPinAccountId = BeingId_zero; +BeingId CharServerHandler::mRenameId = BeingId_zero; bool CharServerHandler::mNeedCreatePin = false; CharServerHandler::CharServerHandler() : @@ -74,8 +74,8 @@ CharServerHandler::CharServerHandler() : { mNewName.clear(); mPinSeed = 0; - mPinAccountId = 0; - mRenameId = 0; + mPinAccountId = BeingId_zero; + mRenameId = BeingId_zero; mNeedCreatePin = false; static const uint16_t _messages[] = @@ -201,7 +201,7 @@ void CharServerHandler::readPlayerData(Net::MessageIn &msg, static_cast<LoginHandler*>(loginHandler)->getToken(); LocalPlayer *const tempPlayer = new LocalPlayer( - msg.readInt32("player id"), 0); + msg.readBeingId("player id"), 0); tempPlayer->setGender(token.sex); PlayerInfoBackend &data = character->data; @@ -337,7 +337,7 @@ void CharServerHandler::deleteCharacter(Net::Character *const character, mSelectedCharacter = character; createOutPacket(CMSG_CHAR_DELETE); - outMsg.writeInt32(mSelectedCharacter->dummy->getId(), "id?"); + outMsg.writeBeingId(mSelectedCharacter->dummy->getId(), "id?"); if (email.empty()) outMsg.writeString("a@a.com", 40, "email"); else @@ -362,7 +362,7 @@ void CharServerHandler::connect() mNetwork->disconnect(); mNetwork->connect(charServer); createOutPacket(CMSG_CHAR_SERVER_CONNECT); - outMsg.writeInt32(token.account_ID, "account id"); + outMsg.writeBeingId(token.account_ID, "account id"); outMsg.writeInt32(token.session_ID1, "session id1"); outMsg.writeInt32(token.session_ID2, "session id2"); outMsg.writeInt16(CLIENT_PROTOCOL_VERSION, "client protocol version"); @@ -497,7 +497,7 @@ void CharServerHandler::processChangeMapServer(Net::MessageIn &msg) void CharServerHandler::processPincodeStatus(Net::MessageIn &msg) { mPinSeed = msg.readInt32("pincode seed"); - mPinAccountId = msg.readInt32("account id"); + mPinAccountId = msg.readBeingId("account id"); const uint16_t state = static_cast<uint16_t>(msg.readInt16("state")); switch (state) { @@ -532,7 +532,7 @@ void CharServerHandler::setNewPincode(const std::string &pin A_UNUSED) // here need ecript pin with mPinSeed and pin values. // createOutPacket(CMSG_CHAR_CREATE_PIN); -// outMsg.writeInt32(mPinAccountId, "account id"); +// outMsg.writeBeingId(mPinAccountId, "account id"); // outMsg.writeString(pin, 4, "encrypted pin"); } @@ -554,13 +554,13 @@ void CharServerHandler::processCharCreate(Net::MessageIn &msg) BLOCK_END("CharServerHandler::processCharCreate") } -void CharServerHandler::renameCharacter(const int id, +void CharServerHandler::renameCharacter(const BeingId id, const std::string &newName) { createOutPacket(CMSG_CHAR_CHECK_RENAME); mRenameId = id; mNewName = newName; - outMsg.writeInt32(id, "char id"); + outMsg.writeBeingId(id, "char id"); outMsg.writeString(newName, 24, "name"); } @@ -569,7 +569,7 @@ void CharServerHandler::processCharCheckRename(Net::MessageIn &msg) if (msg.readInt16("flag")) { createOutPacket(CMSG_CHAR_RENAME); - outMsg.writeInt32(mRenameId, "char id"); + outMsg.writeBeingId(mRenameId, "char id"); } else { diff --git a/src/net/eathena/charserverhandler.h b/src/net/eathena/charserverhandler.h index 6254f9d2c..64968cee4 100644 --- a/src/net/eathena/charserverhandler.h +++ b/src/net/eathena/charserverhandler.h @@ -54,7 +54,7 @@ class CharServerHandler final : public MessageHandler, const uint16_t look, const std::vector<int> &stats) const override final; - void renameCharacter(const int id, + void renameCharacter(const BeingId id, const std::string &newName) override final; void deleteCharacter(Net::Character *const character, @@ -123,8 +123,8 @@ class CharServerHandler final : public MessageHandler, private: static std::string mNewName; static uint32_t mPinSeed; - static uint32_t mPinAccountId; - static uint32_t mRenameId; + static BeingId mPinAccountId; + static BeingId mRenameId; static bool mNeedCreatePin; }; diff --git a/src/net/eathena/chathandler.cpp b/src/net/eathena/chathandler.cpp index 9db670080..d31afa3c9 100644 --- a/src/net/eathena/chathandler.cpp +++ b/src/net/eathena/chathandler.cpp @@ -663,7 +663,7 @@ void ChatHandler::processChatDisplay(Net::MessageIn &msg) { const int len = msg.readInt16("len") - 17; ChatObject *const obj = new ChatObject; - obj->ownerId = msg.readInt32("owner account id"); + obj->ownerId = msg.readBeingId("owner account id"); obj->chatId = msg.readInt32("chat id"); obj->maxUsers = msg.readInt16("max users"); obj->currentUsers = msg.readInt16("current users"); @@ -839,7 +839,7 @@ void ChatHandler::processBeingChat(Net::MessageIn &msg) BLOCK_START("ChatHandler::processBeingChat") int chatMsgLength = msg.readInt16("len") - 8; - Being *const being = actorManager->findBeing(msg.readInt32("being id")); + Being *const being = actorManager->findBeing(msg.readBeingId("being id")); if (chatMsgLength <= 0) { @@ -992,7 +992,7 @@ void ChatHandler::processChatRoomAddMember(Net::MessageIn &msg) void ChatHandler::processChatRoomSettings(Net::MessageIn &msg) { const int sz = msg.readInt16("len") - 17; - const int ownerId = msg.readInt32("owner id"); + const BeingId ownerId = msg.readBeingId("owner id"); const int chatId = msg.readInt32("chat id"); const uint16_t limit = msg.readInt16("limit"); msg.readInt16("users"); @@ -1086,7 +1086,7 @@ void ChatHandler::processChatSilence(Net::MessageIn &msg) void ChatHandler::processChatTalkieBox(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("being id"); + msg.readBeingId("being id"); msg.readString(80, "message"); } @@ -1094,7 +1094,7 @@ void ChatHandler::processBattleChatMessage(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; const int sz = msg.readInt16("len") - 24 - 8; - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readString(24, "nick"); msg.readString(sz, "message"); } @@ -1103,7 +1103,7 @@ void ChatHandler::processScriptMessage(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; const int sz = msg.readInt16("len") - 8; - msg.readInt32("being id"); + msg.readBeingId("being id"); msg.readString(sz, "message"); } diff --git a/src/net/eathena/familyhandler.cpp b/src/net/eathena/familyhandler.cpp index 5b482639f..a21de5ec2 100644 --- a/src/net/eathena/familyhandler.cpp +++ b/src/net/eathena/familyhandler.cpp @@ -86,7 +86,7 @@ void FamilyHandler::askForChild(const Being *const being) return; createOutPacket(CMSG_FAMILY_ASK_FOR_CHILD); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); } void FamilyHandler::processAskForChild(Net::MessageIn &msg) diff --git a/src/net/eathena/friendshandler.cpp b/src/net/eathena/friendshandler.cpp index 91f08a205..43634d9fc 100644 --- a/src/net/eathena/friendshandler.cpp +++ b/src/net/eathena/friendshandler.cpp @@ -80,7 +80,7 @@ void FriendsHandler::handleMessage(Net::MessageIn &msg) void FriendsHandler::processPlayerOnline(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readInt32("char id"); msg.readUInt8("flag"); // 0 - online, 1 - offline } @@ -91,7 +91,7 @@ void FriendsHandler::processFriendsList(Net::MessageIn &msg) const int count = (msg.readInt16("size") - 4) / 32; for (int f = 0; f < count; f ++) { - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readInt32("char id"); msg.readString(24, "name"); } @@ -101,7 +101,7 @@ void FriendsHandler::processRequestAck(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; msg.readInt16("type"); - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readInt32("char id"); msg.readString(24, "name"); } @@ -109,7 +109,7 @@ void FriendsHandler::processRequestAck(Net::MessageIn &msg) void FriendsHandler::processRequest(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readInt32("char id"); msg.readString(24, "name"); } @@ -140,7 +140,7 @@ void FriendsHandler::remove(const int accountId, const int charId) const void FriendsHandler::processDeletePlayer(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readInt32("char id"); } diff --git a/src/net/eathena/gamehandler.cpp b/src/net/eathena/gamehandler.cpp index 2f425b52c..7fa94ab48 100644 --- a/src/net/eathena/gamehandler.cpp +++ b/src/net/eathena/gamehandler.cpp @@ -125,14 +125,14 @@ void GameHandler::connect() } else { - mCharID = 0; + mCharID = BeingId_zero; } } // Send login infos createOutPacket(CMSG_MAP_SERVER_CONNECT); - outMsg.writeInt32(token.account_ID, "account id"); - outMsg.writeInt32(mCharID, "char id"); + outMsg.writeBeingId(token.account_ID, "account id"); + outMsg.writeBeingId(mCharID, "char id"); outMsg.writeInt32(token.session_ID1, "session key1"); outMsg.writeInt32(0, "tick"); outMsg.writeInt8(Being::genderToInt(token.sex), "sex"); @@ -180,7 +180,7 @@ void GameHandler::disconnect2() const void GameHandler::processMapAccountId(Net::MessageIn &msg) { // ignored, because we already know local player account id. - msg.readInt32("account id"); + msg.readBeingId("account id"); } void GameHandler::processMapLogin(Net::MessageIn &msg) diff --git a/src/net/eathena/guildhandler.cpp b/src/net/eathena/guildhandler.cpp index 1a6c29b80..85609581b 100644 --- a/src/net/eathena/guildhandler.cpp +++ b/src/net/eathena/guildhandler.cpp @@ -210,7 +210,7 @@ void GuildHandler::handleMessage(Net::MessageIn &msg) void GuildHandler::processGuildUpdateCoords(Net::MessageIn &msg) { - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const int x = msg.readInt16("x"); const int y = msg.readInt16("y"); if (Ea::taGuild) @@ -241,7 +241,7 @@ void GuildHandler::invite(const std::string &name) const if (being) { createOutPacket(CMSG_GUILD_INVITE); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); outMsg.writeInt32(0, "unused"); outMsg.writeInt32(0, "unused"); } @@ -253,7 +253,7 @@ void GuildHandler::invite(const Being *const being) const return; createOutPacket(CMSG_GUILD_INVITE); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); outMsg.writeInt32(0, "unused"); outMsg.writeInt32(0, "unused"); } @@ -275,7 +275,7 @@ void GuildHandler::leave(const int guildId) const createOutPacket(CMSG_GUILD_LEAVE); outMsg.writeInt32(guildId, "guild id"); - outMsg.writeInt32(localPlayer->getId(), "account id"); + outMsg.writeBeingId(localPlayer->getId(), "account id"); outMsg.writeInt32(PlayerInfo::getCharId(), "char id"); outMsg.writeString("", 40, "message"); } @@ -288,7 +288,7 @@ void GuildHandler::kick(const GuildMember *restrict const member, createOutPacket(CMSG_GUILD_EXPULSION); outMsg.writeInt32(member->getGuild()->getId(), "guild id"); - outMsg.writeInt32(member->getID(), "account id"); + outMsg.writeBeingId(member->getID(), "account id"); outMsg.writeInt32(member->getCharId(), "char id"); outMsg.writeString(reason, 40, "message"); } @@ -339,7 +339,7 @@ void GuildHandler::changeMemberPostion(const GuildMember *const member, createOutPacket(CMSG_GUILD_CHANGE_MEMBER_POS); outMsg.writeInt16(16, "len"); - outMsg.writeInt32(member->getID(), "account id"); + outMsg.writeBeingId(member->getID(), "account id"); outMsg.writeInt32(member->getCharId(), "char id"); outMsg.writeInt32(level, "pos"); } @@ -396,7 +396,7 @@ void GuildHandler::processGuildPositionInfo(Net::MessageIn &msg) void GuildHandler::processGuildMemberLogin(Net::MessageIn &msg) { - const int accountId = msg.readInt32("account id"); + const BeingId accountId = msg.readBeingId("account id"); const int charId = msg.readInt32("char id"); const int online = msg.readInt32("flag"); const Gender::Type gender = Being::intToGender(static_cast<uint8_t>( @@ -445,7 +445,7 @@ void GuildHandler::processGuildExpulsionList(Net::MessageIn &msg) void GuildHandler::processGuildEmblem(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("being id"); + msg.readBeingId("being id"); msg.readInt32("guild id"); msg.readInt16("emblem id"); } @@ -456,7 +456,7 @@ void GuildHandler::requestAlliance(const Being *const being) const return; createOutPacket(CMSG_GUILD_ALLIANCE_REQUEST); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); outMsg.writeInt32(0, "inviter account id"); outMsg.writeInt32(0, "inviter char id"); } @@ -498,7 +498,7 @@ void GuildHandler::requestOpposition(const Being *const being) const return; createOutPacket(CMSG_GUILD_OPPOSITION); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); } void GuildHandler::breakGuild(const std::string &name) const diff --git a/src/net/eathena/homunculushandler.cpp b/src/net/eathena/homunculushandler.cpp index 2bfe358c2..e2441ac14 100644 --- a/src/net/eathena/homunculushandler.cpp +++ b/src/net/eathena/homunculushandler.cpp @@ -127,7 +127,7 @@ void HomunculusHandler::processHomunculusData(Net::MessageIn &msg) { msg.readUInt8("unused"); const int cmd = msg.readUInt8("state"); - const int id = msg.readInt32("homunculus id"); + const BeingId id = msg.readBeingId("homunculus id"); Being *const dstBeing = actorManager->findBeing(id); const int data = msg.readInt32("data"); if (!cmd) // pre init @@ -243,33 +243,34 @@ void HomunculusHandler::setName(const std::string &name) const void HomunculusHandler::moveToMaster() const { - const int id = PlayerInfo::getHomunculusId(); - if (!id) + const BeingId id = PlayerInfo::getHomunculusId(); + if (id == BeingId_zero) return; createOutPacket(CMSG_HOMMERC_MOVE_TO_MASTER); - outMsg.writeInt32(id, "homunculus id"); + outMsg.writeBeingId(id, "homunculus id"); } void HomunculusHandler::move(const int x, const int y) const { - const int id = PlayerInfo::getHomunculusId(); - if (!id) + const BeingId id = PlayerInfo::getHomunculusId(); + if (id == BeingId_zero) return; createOutPacket(CMSG_HOMMERC_MOVE_TO); - outMsg.writeInt32(id, "homunculus id"); + outMsg.writeBeingId(id, "homunculus id"); outMsg.writeCoordinates(static_cast<uint16_t>(x), static_cast<uint16_t>(y), 0U, "position"); } -void HomunculusHandler::attack(const int targetId, const Keep keep) const +void HomunculusHandler::attack(const BeingId targetId, + const Keep keep) const { - const int id = PlayerInfo::getHomunculusId(); - if (!id) + const BeingId id = PlayerInfo::getHomunculusId(); + if (id == BeingId_zero) return; createOutPacket(CMSG_HOMMERC_ATTACK); - outMsg.writeInt32(id, "homunculus id"); - outMsg.writeInt32(targetId, "target id"); + outMsg.writeBeingId(id, "homunculus id"); + outMsg.writeBeingId(targetId, "target id"); outMsg.writeInt8(static_cast<int8_t>(keep == Keep_true ? 1 : 0), "keep"); } diff --git a/src/net/eathena/homunculushandler.h b/src/net/eathena/homunculushandler.h index 5b288eeb6..35955b0ba 100644 --- a/src/net/eathena/homunculushandler.h +++ b/src/net/eathena/homunculushandler.h @@ -45,7 +45,8 @@ class HomunculusHandler final : public MessageHandler, void move(const int x, const int y) const override final; - void attack(const int targetId, const Keep keep) const override final; + void attack(const BeingId targetId, + const Keep keep) const override final; void feed() const override final; diff --git a/src/net/eathena/inventoryhandler.cpp b/src/net/eathena/inventoryhandler.cpp index 3781678cd..186bb5fc5 100644 --- a/src/net/eathena/inventoryhandler.cpp +++ b/src/net/eathena/inventoryhandler.cpp @@ -489,10 +489,10 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg) msg.readInt16("bind on equip"); const ItemInfo &itemInfo = ItemDB::get(itemId); - int floorId; + BeingId floorId; if (mSentPickups.empty()) { - floorId = 0; + floorId = BeingId_zero; } else { @@ -1107,7 +1107,7 @@ void InventoryHandler::processItemDamaged(Net::MessageIn &msg) UNIMPLIMENTEDPACKET; msg.readInt16("position"); - msg.readInt32("account id"); + msg.readBeingId("account id"); } void InventoryHandler::processFavoriteItem(Net::MessageIn &msg) diff --git a/src/net/eathena/itemhandler.cpp b/src/net/eathena/itemhandler.cpp index 0a1629517..ce5dfadfb 100644 --- a/src/net/eathena/itemhandler.cpp +++ b/src/net/eathena/itemhandler.cpp @@ -79,7 +79,7 @@ void ItemHandler::handleMessage(Net::MessageIn &msg) void ItemHandler::processItemDropped(Net::MessageIn &msg) { - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("id"); const int itemId = msg.readInt16("item id"); msg.readInt16("type"); const uint8_t identify = msg.readUInt8("identify"); diff --git a/src/net/eathena/markethandler.cpp b/src/net/eathena/markethandler.cpp index 175429cda..12beafd98 100644 --- a/src/net/eathena/markethandler.cpp +++ b/src/net/eathena/markethandler.cpp @@ -77,7 +77,7 @@ void MarketHandler::processMarketOpen(Net::MessageIn &msg) { const int len = (msg.readInt16("len") - 4) / 13; - mBuyDialog = new BuyDialog(BuyDialog::Market); + mBuyDialog = new BuyDialog(fromInt(BuyDialog::Market, BeingId)); mBuyDialog->postInit(); mBuyDialog->setMoney(PlayerInfo::getAttribute(Attributes::MONEY)); diff --git a/src/net/eathena/mercenaryhandler.cpp b/src/net/eathena/mercenaryhandler.cpp index ebdba730e..82f7b59c2 100644 --- a/src/net/eathena/mercenaryhandler.cpp +++ b/src/net/eathena/mercenaryhandler.cpp @@ -90,7 +90,7 @@ void MercenaryHandler::processMercenaryUpdate(Net::MessageIn &msg) void MercenaryHandler::processMercenaryInfo(Net::MessageIn &msg) { // +++ need create if need mercenary being and update stats - Being *const dstBeing = actorManager->findBeing(msg.readInt32("being id")); + Being *const dstBeing = actorManager->findBeing(msg.readBeingId("being id")); msg.readInt16("atk"); msg.readInt16("matk"); msg.readInt16("hit"); @@ -188,33 +188,34 @@ void MercenaryHandler::fire() void MercenaryHandler::moveToMaster() const { - const int id = PlayerInfo::getMercenaryId(); - if (!id) + const BeingId id = PlayerInfo::getMercenaryId(); + if (id == BeingId_zero) return; createOutPacket(CMSG_HOMMERC_MOVE_TO_MASTER); - outMsg.writeInt32(id, "mercenary id"); + outMsg.writeBeingId(id, "mercenary id"); } void MercenaryHandler::move(const int x, const int y) const { - const int id = PlayerInfo::getMercenaryId(); - if (!id) + const BeingId id = PlayerInfo::getMercenaryId(); + if (id == BeingId_zero) return; createOutPacket(CMSG_HOMMERC_MOVE_TO); - outMsg.writeInt32(id, "mercenary id"); + outMsg.writeBeingId(id, "mercenary id"); outMsg.writeCoordinates(static_cast<uint16_t>(x), static_cast<uint16_t>(y), 0U, "position"); } -void MercenaryHandler::attack(const int targetId, const Keep keep) const +void MercenaryHandler::attack(const BeingId targetId, + const Keep keep) const { - const int id = PlayerInfo::getMercenaryId(); - if (!id) + const BeingId id = PlayerInfo::getMercenaryId(); + if (id == BeingId_zero) return; createOutPacket(CMSG_HOMMERC_ATTACK); - outMsg.writeInt32(id, "mercenary id"); - outMsg.writeInt32(targetId, "target id"); + outMsg.writeBeingId(id, "mercenary id"); + outMsg.writeBeingId(targetId, "target id"); outMsg.writeInt8(static_cast<int8_t>(keep == Keep_true ? 1 : 0), "keep"); } diff --git a/src/net/eathena/mercenaryhandler.h b/src/net/eathena/mercenaryhandler.h index a24f414ff..643f4ec74 100644 --- a/src/net/eathena/mercenaryhandler.h +++ b/src/net/eathena/mercenaryhandler.h @@ -45,7 +45,8 @@ class MercenaryHandler final : public MessageHandler, void move(const int x, const int y) const override final; - void attack(const int targetId, const Keep keep) const override final; + void attack(const BeingId targetId, + const Keep keep) const override final; void talk(const std::string &restrict text) const override final; diff --git a/src/net/eathena/messagein.cpp b/src/net/eathena/messagein.cpp index fda86254a..03b8ddd3a 100644 --- a/src/net/eathena/messagein.cpp +++ b/src/net/eathena/messagein.cpp @@ -105,6 +105,11 @@ int32_t MessageIn::readInt32(const char *const str) return value; } +BeingId MessageIn::readBeingId(const char *const str) +{ + return fromInt(readInt32(str), BeingId); +} + int64_t MessageIn::readInt64(const char *const str) { int64_t value = -1; diff --git a/src/net/eathena/messagein.h b/src/net/eathena/messagein.h index 1a674e129..fb20b6db7 100644 --- a/src/net/eathena/messagein.h +++ b/src/net/eathena/messagein.h @@ -54,6 +54,8 @@ class MessageIn final : public Net::MessageIn int64_t readInt64(const char *const str) override final; + BeingId readBeingId(const char *const str) override final; + uint16_t readId(); }; diff --git a/src/net/eathena/messageout.cpp b/src/net/eathena/messageout.cpp index 084db9418..8ecf8e863 100644 --- a/src/net/eathena/messageout.cpp +++ b/src/net/eathena/messageout.cpp @@ -83,6 +83,11 @@ void MessageOut::writeInt32(const int32_t value, const char *const str) PacketCounters::incOutBytes(4); } +void MessageOut::writeBeingId(const BeingId value, const char *const str) +{ + writeInt32(toInt(value, int32_t), str); +} + #define LOBYTE(w) (static_cast<unsigned char>(w)) #define HIBYTE(w) (static_cast<unsigned char>(( \ static_cast<uint16_t>(w)) >> 8)) diff --git a/src/net/eathena/messageout.h b/src/net/eathena/messageout.h index 11b124e26..4c0074767 100644 --- a/src/net/eathena/messageout.h +++ b/src/net/eathena/messageout.h @@ -56,6 +56,9 @@ class MessageOut final : public Net::MessageOut void writeInt32(const int32_t value, const char *const str) override final; + void writeBeingId(const BeingId value, + const char *const str) override final; + /** * Encodes coordinates and direction in 3 bytes. */ diff --git a/src/net/eathena/npchandler.cpp b/src/net/eathena/npchandler.cpp index e5ff89cfb..2c018dad9 100644 --- a/src/net/eathena/npchandler.cpp +++ b/src/net/eathena/npchandler.cpp @@ -138,23 +138,23 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) mDialog = nullptr; } -void NpcHandler::talk(const int npcId) const +void NpcHandler::talk(const BeingId npcId) const { createOutPacket(CMSG_NPC_TALK); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); outMsg.writeInt8(0, "unused"); } -void NpcHandler::nextDialog(const int npcId) const +void NpcHandler::nextDialog(const BeingId npcId) const { createOutPacket(CMSG_NPC_NEXT_REQUEST); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); } -void NpcHandler::closeDialog(const int npcId) +void NpcHandler::closeDialog(const BeingId npcId) { createOutPacket(CMSG_NPC_CLOSE); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); const NpcDialogs::iterator it = NpcDialog::mNpcDialogs.find(npcId); if (it != NpcDialog::mNpcDialogs.end()) @@ -168,44 +168,48 @@ void NpcHandler::closeDialog(const int npcId) } } -void NpcHandler::listInput(const int npcId, const unsigned char value) const +void NpcHandler::listInput(const BeingId npcId, + const unsigned char value) const { createOutPacket(CMSG_NPC_LIST_CHOICE); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); outMsg.writeInt8(value, "value"); } -void NpcHandler::integerInput(const int npcId, const int value) const +void NpcHandler::integerInput(const BeingId npcId, + const int value) const { createOutPacket(CMSG_NPC_INT_RESPONSE); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); outMsg.writeInt32(value, "value"); } -void NpcHandler::stringInput(const int npcId, const std::string &value) const +void NpcHandler::stringInput(const BeingId npcId, + const std::string &value) const { createOutPacket(CMSG_NPC_STR_RESPONSE); outMsg.writeInt16(static_cast<int16_t>(value.length() + 9), "len"); - outMsg.writeInt32(npcId, "npc ud"); + outMsg.writeBeingId(npcId, "npc id"); outMsg.writeString(value, static_cast<int>(value.length()), "value"); outMsg.writeInt8(0, "null byte"); } -void NpcHandler::buy(const int beingId) const +void NpcHandler::buy(const BeingId beingId) const { createOutPacket(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(beingId, "npc id"); + outMsg.writeBeingId(beingId, "npc id"); outMsg.writeInt8(0, "action"); } -void NpcHandler::sell(const int beingId) const +void NpcHandler::sell(const BeingId beingId) const { createOutPacket(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(beingId, "npc id"); + outMsg.writeBeingId(beingId, "npc id"); outMsg.writeInt8(1, "action"); } -void NpcHandler::buyItem(const int beingId A_UNUSED, const int itemId, +void NpcHandler::buyItem(const BeingId beingId A_UNUSED, + const int itemId, const unsigned char color A_UNUSED, const int amount) const { @@ -215,7 +219,7 @@ void NpcHandler::buyItem(const int beingId A_UNUSED, const int itemId, outMsg.writeInt16(static_cast<int16_t>(itemId), "item id"); } -void NpcHandler::sellItem(const int beingId A_UNUSED, +void NpcHandler::sellItem(const BeingId beingId A_UNUSED, const int itemId, const int amount) const { createOutPacket(CMSG_NPC_SELL_REQUEST); @@ -280,7 +284,7 @@ void NpcHandler::selectAutoSpell(const int skillId) const outMsg.writeInt32(static_cast<int16_t>(skillId), "skill id"); } -int NpcHandler::getNpc(Net::MessageIn &msg) +BeingId NpcHandler::getNpc(Net::MessageIn &msg) { if (msg.getId() == SMSG_NPC_CHOICE || msg.getId() == SMSG_NPC_MESSAGE @@ -289,7 +293,7 @@ int NpcHandler::getNpc(Net::MessageIn &msg) msg.readInt16("len"); } - const int npcId = msg.readInt32("npc id"); + const BeingId npcId = msg.readBeingId("npc id"); const NpcDialogs::const_iterator diag = NpcDialog::mNpcDialogs.find(npcId); mDialog = nullptr; @@ -378,7 +382,7 @@ void NpcHandler::processArea(Net::MessageIn &msg) if (len < 12) return; Being *const dstBeing = actorManager->findBeing( - msg.readInt32("npc id")); + msg.readBeingId("npc id")); const int area = msg.readInt32("area size"); if (dstBeing) dstBeing->setAreaSize(area); diff --git a/src/net/eathena/npchandler.h b/src/net/eathena/npchandler.h index 16e656497..e69366c09 100644 --- a/src/net/eathena/npchandler.h +++ b/src/net/eathena/npchandler.h @@ -39,30 +39,32 @@ class NpcHandler final : public MessageHandler, public Ea::NpcHandler void handleMessage(Net::MessageIn &msg) override final; - void talk(const int npcId) const override final; + void talk(const BeingId npcId) const override final; - void nextDialog(const int npcId) const override final; + void nextDialog(const BeingId npcId) const override final; - void closeDialog(const int npcId) override final; + void closeDialog(const BeingId npcId) override final; - void listInput(const int npcId, + void listInput(const BeingId npcId, const unsigned char value) const override final; - void integerInput(const int npcId, + void integerInput(const BeingId npcId, const int value) const override final; - void stringInput(const int npcId, + void stringInput(const BeingId npcId, const std::string &value) const override final; - void buy(const int beingId) const override final; + void buy(const BeingId beingId) const override final; - void sell(const int beingId) const override final; + void sell(const BeingId beingId) const override final; - void buyItem(const int beingId, const int itemId, + void buyItem(const BeingId beingId, + const int itemId, const unsigned char color, const int amount) const override final; - void sellItem(const int beingId, const int itemId, + void sellItem(const BeingId beingId, + const int itemId, const int amount) const override final; void completeProgressBar() const override final; @@ -79,7 +81,7 @@ class NpcHandler final : public MessageHandler, public Ea::NpcHandler void refine(const int index) const override final; - int getNpc(Net::MessageIn &msg) override final; + BeingId getNpc(Net::MessageIn &msg) override final; void identify(const int index) const override final; diff --git a/src/net/eathena/partyhandler.cpp b/src/net/eathena/partyhandler.cpp index 5f859d12e..d886270ae 100644 --- a/src/net/eathena/partyhandler.cpp +++ b/src/net/eathena/partyhandler.cpp @@ -134,7 +134,7 @@ void PartyHandler::invite(const std::string &name) const if (being) { createOutPacket(CMSG_PARTY_INVITE); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); } else { @@ -165,7 +165,7 @@ void PartyHandler::kick(const Being *const being) const if (being) { createOutPacket(CMSG_PARTY_KICK); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); outMsg.writeString(being->getName(), 24, "player name"); } } @@ -183,7 +183,7 @@ void PartyHandler::kick(const std::string &name) const } createOutPacket(CMSG_PARTY_KICK); - outMsg.writeInt32(m->getID(), "account id"); + outMsg.writeBeingId(m->getID(), "account id"); outMsg.writeString(name, 24, "player name"); } @@ -228,7 +228,7 @@ void PartyHandler::processPartyInvitationStats(Net::MessageIn &msg) void PartyHandler::processPartyMemberInfo(Net::MessageIn &msg) { - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const bool leader = msg.readInt32("leader") == 0U; const int x = msg.readInt16("x"); const int y = msg.readInt16("y"); @@ -320,7 +320,7 @@ void PartyHandler::processPartyInfo(Net::MessageIn &msg) for (int i = 0; i < count; i++) { - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); std::string nick = msg.readString(24, "nick"); std::string map = msg.readString(16, "map name"); const bool leader = msg.readUInt8("leader") == 0U; @@ -384,7 +384,7 @@ void PartyHandler::processPartyMessage(Net::MessageIn &msg) if (msgLength <= 0) return; - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("id"); std::string chatMsg = msg.readString(msgLength, "message"); const size_t pos = chatMsg.find(" : ", 0); @@ -455,7 +455,7 @@ void PartyHandler::changeLeader(const std::string &name) const if (!being) return; createOutPacket(CMSG_PARTY_CHANGE_LEADER); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); } void PartyHandler::allowInvite(const bool allow) const @@ -469,7 +469,7 @@ void PartyHandler::processPartyItemPickup(Net::MessageIn &msg) UNIMPLIMENTEDPACKET; // +++ probably need add option to show pickup notifications // in party tab - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readInt16("item id"); msg.readUInt8("identify"); msg.readUInt8("attribute"); @@ -483,9 +483,9 @@ void PartyHandler::processPartyItemPickup(Net::MessageIn &msg) void PartyHandler::processPartyLeader(Net::MessageIn &msg) { PartyMember *const oldMember = Ea::taParty->getMember( - msg.readInt32("old leder id")); + msg.readBeingId("old leder id")); PartyMember *const newMember = Ea::taParty->getMember( - msg.readInt32("new leder id")); + msg.readBeingId("new leder id")); if (oldMember) oldMember->setLeader(false); if (newMember) @@ -494,11 +494,23 @@ void PartyHandler::processPartyLeader(Net::MessageIn &msg) void PartyHandler::processPartyInvited(Net::MessageIn &msg) { - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const std::string partyName = msg.readString(24, "party name"); + std::string nick; + + if (actorManager) + { + const Being *const being = actorManager->findBeing(id); + if (being) + { + if (being->getType() == ActorType::Player) + nick = being->getName(); + } + } + if (socialWindow) - socialWindow->showPartyInvite(partyName, "", id); + socialWindow->showPartyInvite(partyName, nick, 0); } } // namespace EAthena diff --git a/src/net/eathena/pethandler.cpp b/src/net/eathena/pethandler.cpp index 71d4d17f2..32f902e80 100644 --- a/src/net/eathena/pethandler.cpp +++ b/src/net/eathena/pethandler.cpp @@ -143,7 +143,7 @@ void PetHandler::catchPet(const Being *const being) const return; createOutPacket(CMSG_PET_CATCH); - outMsg.writeInt32(being->getId(), "monster id"); + outMsg.writeBeingId(being->getId(), "monster id"); } void PetHandler::sendPetMessage(const int data) const @@ -160,7 +160,7 @@ void PetHandler::setName(const std::string &name) const void PetHandler::processPetMessage(Net::MessageIn &msg) { - const int id = msg.readInt32("pet id"); + const BeingId id = msg.readBeingId("pet id"); const int data = msg.readInt32("param"); Being *const dstBeing = actorManager->findBeing(id); if (!dstBeing) @@ -228,7 +228,7 @@ void PetHandler::processEggsList(Net::MessageIn &msg) void PetHandler::processPetData(Net::MessageIn &msg) { const int cmd = msg.readUInt8("type"); - const int id = msg.readInt32("pet id"); + const BeingId id = msg.readBeingId("pet id"); Being *const dstBeing = actorManager->findBeing(id); const int data = msg.readInt32("data"); if (!cmd) // pre init diff --git a/src/net/eathena/playerhandler.cpp b/src/net/eathena/playerhandler.cpp index a2bb8b83e..a4e4586f2 100644 --- a/src/net/eathena/playerhandler.cpp +++ b/src/net/eathena/playerhandler.cpp @@ -205,10 +205,11 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) } } -void PlayerHandler::attack(const int id, const Keep keep) const +void PlayerHandler::attack(const BeingId id, + const Keep keep) const { createOutPacket(CMSG_PLAYER_CHANGE_ACT); - outMsg.writeInt32(id, "target id"); + outMsg.writeBeingId(id, "target id"); if (keep == Keep_true) outMsg.writeInt8(7, "action"); else @@ -251,7 +252,7 @@ void PlayerHandler::pickUp(const FloorItem *const floorItem) const return; createOutPacket(CMSG_ITEM_PICKUP); - outMsg.writeInt32(floorItem->getId(), "object id"); + outMsg.writeBeingId(floorItem->getId(), "object id"); EAthena::InventoryHandler *const handler = static_cast<EAthena::InventoryHandler*>(inventoryHandler); if (handler) @@ -484,7 +485,7 @@ void PlayerHandler::processPlayerGetExp(Net::MessageIn &msg) { if (!localPlayer) return; - const int id = msg.readInt32("player id"); + const BeingId id = msg.readBeingId("player id"); const int exp = msg.readInt32("exp amount"); const int stat = msg.readInt16("exp type"); const bool fromQuest = msg.readInt16("is from quest"); @@ -538,7 +539,7 @@ void PlayerHandler::processPvpInfo(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; msg.readInt32("char id"); - msg.readInt32("account id"); + msg.readBeingId("account id"); msg.readInt32("pvp won"); msg.readInt32("pvp lost"); msg.readInt32("pvp point"); diff --git a/src/net/eathena/playerhandler.h b/src/net/eathena/playerhandler.h index 6d7d6a9e1..fc84db326 100644 --- a/src/net/eathena/playerhandler.h +++ b/src/net/eathena/playerhandler.h @@ -39,7 +39,8 @@ class PlayerHandler final : public MessageHandler, public Ea::PlayerHandler void handleMessage(Net::MessageIn &msg) override final; - void attack(const int id, const Keep keep) const override final; + void attack(const BeingId id, + const Keep keep) const override final; void stopAttack() const override final; void emote(const uint8_t emoteId) const override final; diff --git a/src/net/eathena/skillhandler.cpp b/src/net/eathena/skillhandler.cpp index 27f4b136a..fb8cf39e7 100644 --- a/src/net/eathena/skillhandler.cpp +++ b/src/net/eathena/skillhandler.cpp @@ -159,12 +159,12 @@ void SkillHandler::handleMessage(Net::MessageIn &msg) } void SkillHandler::useBeing(const int id, const int level, - const int beingId) const + const BeingId beingId) const { createOutPacket(CMSG_SKILL_USE_BEING); outMsg.writeInt16(static_cast<int16_t>(level), "skill level"); outMsg.writeInt16(static_cast<int16_t>(id), "skill id"); - outMsg.writeInt32(beingId, "target id"); + outMsg.writeInt32(toInt(beingId, int), "target id"); } void SkillHandler::usePos(const int id, const int level, @@ -424,7 +424,7 @@ void SkillHandler::processSkillFailed(Net::MessageIn &msg) void SkillHandler::processSkillSnap(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("being id"); + msg.readBeingId("being id"); msg.readInt16("x"); msg.readInt16("y"); } @@ -470,7 +470,7 @@ void SkillHandler::processSkillUnitUpdate(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("being id"); + msg.readBeingId("being id"); } void SkillHandler::processSkillArrowCreateList(Net::MessageIn &msg) @@ -496,7 +496,7 @@ void SkillHandler::processSkillDevotionEffect(Net::MessageIn &msg) { UNIMPLIMENTEDPACKET; - msg.readInt32("being id"); + msg.readBeingId("being id"); for (int f = 0; f < 5; f ++) msg.readInt32("devotee id"); msg.readInt16("range"); diff --git a/src/net/eathena/skillhandler.h b/src/net/eathena/skillhandler.h index 2cfb4b89f..2cef21777 100644 --- a/src/net/eathena/skillhandler.h +++ b/src/net/eathena/skillhandler.h @@ -39,13 +39,16 @@ class SkillHandler final : public MessageHandler, public Ea::SkillHandler void handleMessage(Net::MessageIn &msg) override final; - void useBeing(const int id, const int level, - const int beingId) const override final; + void useBeing(const int id, + const int level, + const BeingId beingId) const override final; - void usePos(const int id, const int level, + void usePos(const int id, + const int level, const int x, const int y) const override final; - void usePos(const int id, const int level, + void usePos(const int id, + const int level, const int x, const int y, const std::string &text) const override final; diff --git a/src/net/eathena/tradehandler.cpp b/src/net/eathena/tradehandler.cpp index 5b1c92ac1..4f036d09b 100644 --- a/src/net/eathena/tradehandler.cpp +++ b/src/net/eathena/tradehandler.cpp @@ -116,7 +116,7 @@ void TradeHandler::request(const Being *const being) const return; createOutPacket(CMSG_TRADE_REQUEST); - outMsg.writeInt32(being->getId(), "player id"); + outMsg.writeBeingId(being->getId(), "player id"); } void TradeHandler::respond(const bool accept) const diff --git a/src/net/eathena/vendinghandler.cpp b/src/net/eathena/vendinghandler.cpp index 9ba6bfc7b..1bbe491cf 100644 --- a/src/net/eathena/vendinghandler.cpp +++ b/src/net/eathena/vendinghandler.cpp @@ -116,7 +116,7 @@ void VendingHandler::processOpenReq(Net::MessageIn &msg) void VendingHandler::processShowBoard(Net::MessageIn &msg) { - const int id = msg.readInt32("owner id"); + const BeingId id = msg.readBeingId("owner id"); const std::string shopName = msg.readString(80, "shop name"); Being *const dstBeing = actorManager->findBeing(id); if (dstBeing) @@ -125,7 +125,7 @@ void VendingHandler::processShowBoard(Net::MessageIn &msg) void VendingHandler::processHideBoard(Net::MessageIn &msg) { - const int id = msg.readInt32("owner id"); + const BeingId id = msg.readBeingId("owner id"); Being *const dstBeing = actorManager->findBeing(id); if (dstBeing) dstBeing->setSellBoard(std::string()); @@ -139,7 +139,7 @@ void VendingHandler::processHideBoard(Net::MessageIn &msg) void VendingHandler::processItemsList(Net::MessageIn &msg) { const int count = (msg.readInt16("len") - 12) / 22; - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("id"); Being *const being = actorManager->findBeing(id); if (!being) return; @@ -223,7 +223,7 @@ void VendingHandler::open(const Being *const being) const return; createOutPacket(CMSG_VENDING_LIST_REQ); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); } void VendingHandler::buy(const Being *const being, @@ -235,7 +235,7 @@ void VendingHandler::buy(const Being *const being, createOutPacket(CMSG_VENDING_BUY); outMsg.writeInt16(12, "len"); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); outMsg.writeInt16(static_cast<int16_t>(amount), "amount"); outMsg.writeInt16(static_cast<int16_t>(index), "index"); } @@ -250,7 +250,7 @@ void VendingHandler::buy2(const Being *const being, createOutPacket(CMSG_VENDING_BUY2); outMsg.writeInt16(16, "len"); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); outMsg.writeInt32(vendId, "vend id"); outMsg.writeInt16(static_cast<int16_t>(amount), "amount"); outMsg.writeInt16(static_cast<int16_t>(index), "index"); diff --git a/src/net/homunculushandler.h b/src/net/homunculushandler.h index c63ed8bba..346fcef49 100644 --- a/src/net/homunculushandler.h +++ b/src/net/homunculushandler.h @@ -23,6 +23,7 @@ #ifdef EATHENA_SUPPORT +#include "enums/simpletypes/beingid.h" #include "enums/simpletypes/keep.h" #include <string> @@ -44,7 +45,8 @@ class HomunculusHandler notfinal virtual void move(const int x, const int y) const = 0; - virtual void attack(const int targetId, const Keep keep) const = 0; + virtual void attack(const BeingId targetId, + const Keep keep) const = 0; virtual void feed() const = 0; diff --git a/src/net/mercenaryhandler.h b/src/net/mercenaryhandler.h index 5c1517975..d39267c5f 100644 --- a/src/net/mercenaryhandler.h +++ b/src/net/mercenaryhandler.h @@ -23,6 +23,7 @@ #ifdef EATHENA_SUPPORT +#include "enums/simpletypes/beingid.h" #include "enums/simpletypes/keep.h" #include <string> @@ -46,7 +47,8 @@ class MercenaryHandler notfinal virtual void move(const int x, const int y) const = 0; - virtual void attack(const int targetId, const Keep keep) const = 0; + virtual void attack(const BeingId targetId, + const Keep keep) const = 0; virtual void talk(const std::string &restrict text) const = 0; diff --git a/src/net/messagein.h b/src/net/messagein.h index cb25a3fde..154b55b3e 100644 --- a/src/net/messagein.h +++ b/src/net/messagein.h @@ -23,6 +23,8 @@ #ifndef NET_MESSAGEIN_H #define NET_MESSAGEIN_H +#include "enums/simpletypes/beingid.h" + #include <string> #include "localconsts.h" @@ -74,6 +76,8 @@ class MessageIn notfinal virtual int64_t readInt64(const char *const str) = 0; + virtual BeingId readBeingId(const char *const str) = 0; + /** * Reads a special 3 byte block used by eAthena, containing x and y * coordinates and direction. diff --git a/src/net/messageout.h b/src/net/messageout.h index 13a4eae1b..048afc70c 100644 --- a/src/net/messageout.h +++ b/src/net/messageout.h @@ -23,6 +23,8 @@ #ifndef NET_MESSAGEOUT_H #define NET_MESSAGEOUT_H +#include "enums/simpletypes/beingid.h" + #include <string> #include "localconsts.h" @@ -47,13 +49,16 @@ class MessageOut notfinal const char *const str); /**< Writes a short. */ - virtual void writeInt16(int16_t value, + virtual void writeInt16(const int16_t value, const char *const str) = 0; /**< Writes a long. */ - virtual void writeInt32(int32_t value, + virtual void writeInt32(const int32_t value, const char *const str) = 0; + virtual void writeBeingId(const BeingId value, + const char *const str) = 0; + /** * Writes a string. If a fixed length is not given (-1), it is stored * as a short at the start of the string. diff --git a/src/net/npchandler.h b/src/net/npchandler.h index 42eaabb00..83c896d1c 100644 --- a/src/net/npchandler.h +++ b/src/net/npchandler.h @@ -27,6 +27,8 @@ #include "enums/being/cookingtype.h" +#include "enums/simpletypes/beingid.h" + #include "localconsts.h" namespace Net @@ -40,31 +42,34 @@ class NpcHandler notfinal virtual ~NpcHandler() { } - virtual int getNpc(Net::MessageIn &msg) = 0; + virtual BeingId getNpc(Net::MessageIn &msg) = 0; - virtual void talk(const int npcId) const = 0; + virtual void talk(const BeingId npcId) const = 0; - virtual void nextDialog(const int npcId) const = 0; + virtual void nextDialog(const BeingId npcId) const = 0; - virtual void closeDialog(const int npcId) = 0; + virtual void closeDialog(const BeingId npcId) = 0; - virtual void listInput(const int npcId, + virtual void listInput(const BeingId npcId, const unsigned char value) const = 0; - virtual void integerInput(const int npcId, const int value) const = 0; + virtual void integerInput(const BeingId npcId, + const int value) const = 0; - virtual void stringInput(const int npcId, + virtual void stringInput(const BeingId npcId, const std::string &value) const = 0; - virtual void buy(const int beingId) const = 0; + virtual void buy(const BeingId beingId) const = 0; - virtual void sell(const int beingId) const = 0; + virtual void sell(const BeingId beingId) const = 0; - virtual void buyItem(const int beingId, const int itemId, + virtual void buyItem(const BeingId beingId, + const int itemId, const unsigned char color, const int amount) const = 0; - virtual void sellItem(const int beingId, const int itemId, + virtual void sellItem(const BeingId beingId, + const int itemId, const int amount) const = 0; virtual void completeProgressBar() const = 0; diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h index 44001e7c4..5fde7db54 100644 --- a/src/net/playerhandler.h +++ b/src/net/playerhandler.h @@ -27,6 +27,7 @@ #include "enums/being/beingaction.h" +#include "enums/simpletypes/beingid.h" #include "enums/simpletypes/keep.h" #include "enums/simpletypes/notify.h" @@ -41,7 +42,8 @@ class PlayerHandler notfinal virtual ~PlayerHandler() { } - virtual void attack(const int id, const Keep keep) const = 0; + virtual void attack(const BeingId id, + const Keep keep) const = 0; virtual void stopAttack() const = 0; diff --git a/src/net/skillhandler.h b/src/net/skillhandler.h index 9c9318c66..996101149 100644 --- a/src/net/skillhandler.h +++ b/src/net/skillhandler.h @@ -23,6 +23,8 @@ #ifndef NET_SKILLHANDLER_H #define NET_SKILLHANDLER_H +#include "enums/simpletypes/beingid.h" + #include <iosfwd> #include "localconsts.h" @@ -35,13 +37,16 @@ class SkillHandler notfinal virtual ~SkillHandler() { } - virtual void useBeing(const int id, const int level, - const int beingId) const = 0; + virtual void useBeing(const int id, + const int level, + const BeingId beingId) const = 0; - virtual void usePos(const int id, const int level, + virtual void usePos(const int id, + const int level, const int x, const int y) const = 0; - virtual void usePos(const int id, const int level, + virtual void usePos(const int id, + const int level, const int x, const int y, const std::string &text) const = 0; diff --git a/src/net/tmwa/adminhandler.cpp b/src/net/tmwa/adminhandler.cpp index 216a33cb7..64638ad46 100644 --- a/src/net/tmwa/adminhandler.cpp +++ b/src/net/tmwa/adminhandler.cpp @@ -86,10 +86,10 @@ void AdminHandler::hide(const bool h A_UNUSED) const outMsg.writeInt32(0, "unused"); } -void AdminHandler::kick(const int playerId) const +void AdminHandler::kick(const BeingId playerId) const { createOutPacket(CMSG_ADMIN_KICK); - outMsg.writeInt32(playerId, "account id"); + outMsg.writeBeingId(playerId, "account id"); } void AdminHandler::kickAll() const diff --git a/src/net/tmwa/adminhandler.h b/src/net/tmwa/adminhandler.h index 35a4ccead..a98d6d850 100644 --- a/src/net/tmwa/adminhandler.h +++ b/src/net/tmwa/adminhandler.h @@ -45,7 +45,7 @@ class AdminHandler final : public MessageHandler, public Ea::AdminHandler void hide(const bool h) const override final; - void kick(const int playerId) const override final; + void kick(const BeingId playerId) const override final; void kickAll() const override final; diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 20ab2cffa..0191953a4 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -101,10 +101,10 @@ BeingHandler::BeingHandler(const bool enableSync) : beingHandler = this; } -void BeingHandler::requestNameById(const int id) const +void BeingHandler::requestNameById(const BeingId id) const { createOutPacket(CMSG_NAME_REQUEST); - outMsg.writeInt32(id, "being id"); + outMsg.writeBeingId(id, "being id"); } void BeingHandler::handleMessage(Net::MessageIn &msg) @@ -267,7 +267,7 @@ void BeingHandler::processBeingChangeLook(Net::MessageIn &msg) } Being *const dstBeing = actorManager->findBeing( - msg.readInt32("being id")); + msg.readBeingId("being id")); const uint8_t type = msg.readUInt8("type"); const int16_t id = static_cast<int16_t>(msg.readUInt8("id")); @@ -292,7 +292,7 @@ void BeingHandler::processBeingChangeLook2(Net::MessageIn &msg) } Being *const dstBeing = actorManager->findBeing( - msg.readInt32("being id")); + msg.readBeingId("being id")); const uint8_t type = msg.readUInt8("type"); int id2 = 0; @@ -427,7 +427,7 @@ void BeingHandler::processPlayerUpdate1(Net::MessageIn &msg) } // An update about a player, potentially including movement. - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); @@ -435,7 +435,7 @@ void BeingHandler::processPlayerUpdate1(Net::MessageIn &msg) << 16; const int16_t job = msg.readInt16("job"); int disguiseId = 0; - if (id < 110000000 && job >= 1000) + if (toInt(id, int) < 110000000 && job >= 1000) disguiseId = job; Being *dstBeing = actorManager->findBeing(id); @@ -579,7 +579,7 @@ void BeingHandler::processPlayerUpdate2(Net::MessageIn &msg) } // An update about a player, potentially including movement. - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); @@ -587,7 +587,7 @@ void BeingHandler::processPlayerUpdate2(Net::MessageIn &msg) << 16; const int16_t job = msg.readInt16("job"); int disguiseId = 0; - if (id < 110000000 && job >= 1000) + if (toInt(id, int) < 110000000 && job >= 1000) disguiseId = job; Being *dstBeing = actorManager->findBeing(id); @@ -727,7 +727,7 @@ void BeingHandler::processPlayerMove(Net::MessageIn &msg) } // An update about a player, potentially including movement. - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); @@ -735,7 +735,7 @@ void BeingHandler::processPlayerMove(Net::MessageIn &msg) << 16; const int16_t job = msg.readInt16("job"); int disguiseId = 0; - if (id < 110000000 && job >= 1000) + if (toInt(id, int) < 110000000 && job >= 1000) disguiseId = job; Being *dstBeing = actorManager->findBeing(id); @@ -904,15 +904,15 @@ void BeingHandler::processBeingVisible(Net::MessageIn &msg) return; } - int spawnId; + BeingId spawnId; // Information about a being in range - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); if (id == mSpawnId) spawnId = mSpawnId; else - spawnId = 0; - mSpawnId = 0; + spawnId = BeingId_zero; + mSpawnId = BeingId_zero; int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); @@ -936,7 +936,7 @@ void BeingHandler::processBeingVisible(Net::MessageIn &msg) { // Being with id >= 110000000 and job 0 are better // known as ghosts, so don't create those. - if (job == 0 && id >= 110000000) + if (job == 0 && toInt(id, int) >= 110000000) { BLOCK_END("BeingHandler::processBeingVisibleOrMove") return; @@ -969,7 +969,7 @@ void BeingHandler::processBeingVisible(Net::MessageIn &msg) if (dstBeing->getType() == ActorType::Player) dstBeing->setMoveTime(); - if (spawnId) + if (spawnId != BeingId_zero) { dstBeing->setAction(BeingAction::SPAWN, 0); } @@ -1111,15 +1111,15 @@ void BeingHandler::processBeingMove(Net::MessageIn &msg) return; } - int spawnId; + BeingId spawnId; // Information about a being in range - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); if (id == mSpawnId) spawnId = mSpawnId; else - spawnId = 0; - mSpawnId = 0; + spawnId = BeingId_zero; + mSpawnId = BeingId_zero; int16_t speed = msg.readInt16("speed"); const uint16_t stunMode = msg.readInt16("opt1"); uint32_t statusEffects = msg.readInt16("opt2"); @@ -1143,7 +1143,7 @@ void BeingHandler::processBeingMove(Net::MessageIn &msg) { // Being with id >= 110000000 and job 0 are better // known as ghosts, so don't create those. - if (job == 0 && id >= 110000000) + if (job == 0 && toInt(id, int) >= 110000000) { BLOCK_END("BeingHandler::processBeingVisibleOrMove") return; @@ -1176,7 +1176,7 @@ void BeingHandler::processBeingMove(Net::MessageIn &msg) if (dstBeing->getType() == ActorType::Player) dstBeing->setMoveTime(); - if (spawnId) + if (spawnId != BeingId_zero) dstBeing->setAction(BeingAction::SPAWN, 0); // Prevent division by 0 when calculating frame @@ -1296,7 +1296,7 @@ void BeingHandler::processBeingSpawn(Net::MessageIn &msg) { BLOCK_START("BeingHandler::processBeingSpawn") // skipping this packet - mSpawnId = msg.readInt32("being id"); + mSpawnId = msg.readBeingId("being id"); msg.readInt16("speed"); msg.readInt16("opt1"); msg.readInt16("opt2"); @@ -1328,7 +1328,7 @@ void BeingHandler::processBeingStatusChange(Net::MessageIn &msg) // Status change const uint16_t status = msg.readInt16("status"); - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); const Enable flag = fromBool( msg.readUInt8("flag: 0: stop, 1: start"), Enable); @@ -1352,7 +1352,7 @@ void BeingHandler::processBeingMove2(Net::MessageIn &msg) * later versions of eAthena for both mobs and * players */ - Being *const dstBeing = actorManager->findBeing(msg.readInt32("being id")); + Being *const dstBeing = actorManager->findBeing(msg.readBeingId("being id")); /* * This packet doesn't have enough info to actually @@ -1387,7 +1387,7 @@ void BeingHandler::processBeingChangeDirection(Net::MessageIn &msg) return; } - Being *const dstBeing = actorManager->findBeing(msg.readInt32("being id")); + Being *const dstBeing = actorManager->findBeing(msg.readBeingId("being id")); if (!dstBeing) { @@ -1470,7 +1470,7 @@ void BeingHandler::processPlaterStatusChange(Net::MessageIn &msg) } // Change in players' flags - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); Being *const dstBeing = actorManager->findBeing(id); if (!dstBeing) return; @@ -1499,7 +1499,7 @@ void BeingHandler::processBeingResurrect(Net::MessageIn &msg) // A being changed mortality status - const int id = msg.readInt32("being id"); + const BeingId id = msg.readBeingId("being id"); Being *const dstBeing = actorManager->findBeing(id); if (!dstBeing) { @@ -1525,7 +1525,7 @@ void BeingHandler::processPlayerGuilPartyInfo(Net::MessageIn &msg) return; } - Being *const dstBeing = actorManager->findBeing(msg.readInt32("being id")); + Being *const dstBeing = actorManager->findBeing(msg.readBeingId("being id")); if (dstBeing) { @@ -1562,7 +1562,7 @@ void BeingHandler::processBeingSelfEffect(Net::MessageIn &msg) return; } - const int id = static_cast<uint32_t>(msg.readInt32("being id")); + const BeingId id = msg.readBeingId("being id"); Being *const being = actorManager->findBeing(id); if (!being) { @@ -1598,7 +1598,7 @@ void BeingHandler::processIpResponse(Net::MessageIn &msg) return; } - Being *const dstBeing = actorManager->findBeing(msg.readInt32("being id")); + Being *const dstBeing = actorManager->findBeing(msg.readBeingId("being id")); if (dstBeing) dstBeing->setIp(ipToString(msg.readInt32("ip address"))); BLOCK_END("BeingHandler::processIpResponse") diff --git a/src/net/tmwa/beinghandler.h b/src/net/tmwa/beinghandler.h index 64678939b..20badffe0 100644 --- a/src/net/tmwa/beinghandler.h +++ b/src/net/tmwa/beinghandler.h @@ -39,7 +39,7 @@ class BeingHandler final : public MessageHandler, public Ea::BeingHandler void handleMessage(Net::MessageIn &msg) override final; - void requestNameById(const int id) const override final; + void requestNameById(const BeingId id) const override final; void undress(Being *const being) const override final; diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp index 970d6a9c6..f3a8ab0c6 100644 --- a/src/net/tmwa/charserverhandler.cpp +++ b/src/net/tmwa/charserverhandler.cpp @@ -141,7 +141,7 @@ void CharServerHandler::readPlayerData(Net::MessageIn &msg, static_cast<LoginHandler*>(loginHandler)->getToken(); LocalPlayer *const tempPlayer = new LocalPlayer( - msg.readInt32("account id"), 0); + msg.readBeingId("account id"), 0); tempPlayer->setGender(token.sex); PlayerInfoBackend &data = character->data; @@ -288,7 +288,7 @@ void CharServerHandler::deleteCharacter(Net::Character *const character, mSelectedCharacter = character; createOutPacket(CMSG_CHAR_DELETE); - outMsg.writeInt32(mSelectedCharacter->dummy->getId(), "id?"); + outMsg.writeBeingId(mSelectedCharacter->dummy->getId(), "id?"); outMsg.writeString("a@a.com", 40, "email"); } @@ -310,7 +310,7 @@ void CharServerHandler::connect() mNetwork->disconnect(); mNetwork->connect(charServer); createOutPacket(CMSG_CHAR_SERVER_CONNECT); - outMsg.writeInt32(token.account_ID, "account id"); + outMsg.writeBeingId(token.account_ID, "account id"); outMsg.writeInt32(token.session_ID1, "session id1"); outMsg.writeInt32(token.session_ID2, "session id2"); // [Fate] The next word is unused by the old char server, so we squeeze in @@ -502,7 +502,7 @@ void CharServerHandler::processCharCreate2(Net::MessageIn &msg) BLOCK_END("CharServerHandler::processCharCreate2") } -void CharServerHandler::renameCharacter(const int id A_UNUSED, +void CharServerHandler::renameCharacter(const BeingId id A_UNUSED, const std::string &newName A_UNUSED) { } diff --git a/src/net/tmwa/charserverhandler.h b/src/net/tmwa/charserverhandler.h index 20a162eb1..2d73d5a22 100644 --- a/src/net/tmwa/charserverhandler.h +++ b/src/net/tmwa/charserverhandler.h @@ -57,7 +57,7 @@ class CharServerHandler final : public MessageHandler, void deleteCharacter(Net::Character *const character, const std::string &email) override final; - void renameCharacter(const int id, + void renameCharacter(const BeingId id, const std::string &newName) override final; void switchCharacter() const override final; diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index ab8036c8c..ed3a1318f 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -615,7 +615,7 @@ void ChatHandler::processBeingChat(Net::MessageIn &msg) BLOCK_START("ChatHandler::processBeingChat") const bool channels = msg.getId() == SMSG_BEING_CHAT2; int chatMsgLength = msg.readInt16("len") - 8; - Being *const being = actorManager->findBeing(msg.readInt32("being id")); + Being *const being = actorManager->findBeing(msg.readBeingId("being id")); if (!being) { BLOCK_END("ChatHandler::processBeingChat") diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp index f804b61f2..83bc6e966 100644 --- a/src/net/tmwa/gamehandler.cpp +++ b/src/net/tmwa/gamehandler.cpp @@ -113,14 +113,14 @@ void GameHandler::connect() } else { - mCharID = 0; + mCharID = BeingId_zero; } } // Send login infos createOutPacket(CMSG_MAP_SERVER_CONNECT); - outMsg.writeInt32(token.account_ID, "account id"); - outMsg.writeInt32(mCharID, "char id"); + outMsg.writeBeingId(token.account_ID, "account id"); + outMsg.writeBeingId(mCharID, "char id"); outMsg.writeInt32(token.session_ID1, "session id1"); outMsg.writeInt32(token.session_ID2, "session id2"); outMsg.writeInt8(Being::genderToInt(token.sex), "gender"); diff --git a/src/net/tmwa/guildhandler.cpp b/src/net/tmwa/guildhandler.cpp index f58f873a4..c552cfaef 100644 --- a/src/net/tmwa/guildhandler.cpp +++ b/src/net/tmwa/guildhandler.cpp @@ -222,7 +222,7 @@ void GuildHandler::invite(const std::string &name) const if (being) { createOutPacket(CMSG_GUILD_INVITE); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); outMsg.writeInt32(0, "unused"); outMsg.writeInt32(0, "unused"); } @@ -234,7 +234,7 @@ void GuildHandler::invite(const Being *const being) const return; createOutPacket(CMSG_GUILD_INVITE); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); outMsg.writeInt32(0, "unused"); outMsg.writeInt32(0, "unused"); } @@ -255,7 +255,7 @@ void GuildHandler::leave(const int guildId) const createOutPacket(CMSG_GUILD_LEAVE); outMsg.writeInt32(guildId, "guild id"); - outMsg.writeInt32(localPlayer->getId(), "account id"); + outMsg.writeBeingId(localPlayer->getId(), "account id"); outMsg.writeInt32(PlayerInfo::getCharId(), "char id"); outMsg.writeString("", 40, "message"); } @@ -268,7 +268,7 @@ void GuildHandler::kick(const GuildMember *restrict const member, createOutPacket(CMSG_GUILD_EXPULSION); outMsg.writeInt32(member->getGuild()->getId(), "guild id"); - outMsg.writeInt32(member->getID(), "account id"); + outMsg.writeBeingId(member->getID(), "account id"); outMsg.writeInt32(member->getCharId(), "char id"); outMsg.writeString(reason, 40, "message"); } @@ -318,7 +318,7 @@ void GuildHandler::changeMemberPostion(const GuildMember *const member, createOutPacket(CMSG_GUILD_CHANGE_MEMBER_POS); outMsg.writeInt16(16, "len"); - outMsg.writeInt32(member->getID(), "account id"); + outMsg.writeBeingId(member->getID(), "account id"); outMsg.writeInt32(member->getCharId(), "char id"); outMsg.writeInt32(level, "position"); } @@ -379,7 +379,7 @@ void GuildHandler::processGuildPositionInfo(Net::MessageIn &msg) void GuildHandler::processGuildMemberLogin(Net::MessageIn &msg) { - const int accountId = msg.readInt32("account id"); + const BeingId accountId = msg.readBeingId("account id"); const int charId = msg.readInt32("char id"); const int online = msg.readInt32("flag"); if (Ea::taGuild) diff --git a/src/net/tmwa/guildmanager.cpp b/src/net/tmwa/guildmanager.cpp index 7931087a9..9b584f14a 100644 --- a/src/net/tmwa/guildmanager.cpp +++ b/src/net/tmwa/guildmanager.cpp @@ -201,7 +201,8 @@ void GuildManager::updateList() const int status = atoi(name.substr(sz - 1).c_str()); name = name.substr(0, sz - 1); - GuildMember *const m = guild->addMember(i, 0, name); + GuildMember *const m = guild->addMember( + fromInt(i, BeingId), 0, name); if (m) { m->setOnline(status & 1); diff --git a/src/net/tmwa/homunculushandler.cpp b/src/net/tmwa/homunculushandler.cpp index 8ffbb6ed4..1a0a89077 100644 --- a/src/net/tmwa/homunculushandler.cpp +++ b/src/net/tmwa/homunculushandler.cpp @@ -54,7 +54,7 @@ void HomunculusHandler::move(const int x A_UNUSED, const int y A_UNUSED) const { } -void HomunculusHandler::attack(const int targetId A_UNUSED, +void HomunculusHandler::attack(const BeingId targetId A_UNUSED, const Keep keep A_UNUSED) const { } diff --git a/src/net/tmwa/homunculushandler.h b/src/net/tmwa/homunculushandler.h index 9aec1eed6..a54079382 100644 --- a/src/net/tmwa/homunculushandler.h +++ b/src/net/tmwa/homunculushandler.h @@ -46,7 +46,8 @@ class HomunculusHandler final : public MessageHandler, void move(const int x, const int y) const override final; - void attack(const int targetId, const Keep keep) const override final; + void attack(const BeingId targetId, + const Keep keep) const override final; void feed() const override final; diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 28db6fa69..d1b7014f3 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -348,10 +348,10 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg) const ItemInfo &itemInfo = ItemDB::get(itemId); const unsigned char err = msg.readUInt8("status"); - int floorId; + BeingId floorId; if (mSentPickups.empty()) { - floorId = 0; + floorId = BeingId_zero; } else { diff --git a/src/net/tmwa/itemhandler.cpp b/src/net/tmwa/itemhandler.cpp index 0e74172db..7ad3f733a 100644 --- a/src/net/tmwa/itemhandler.cpp +++ b/src/net/tmwa/itemhandler.cpp @@ -70,7 +70,7 @@ void ItemHandler::handleMessage(Net::MessageIn &msg) void ItemHandler::processItemDropped(Net::MessageIn &msg) { - const int id = msg.readInt32("item object id"); + const BeingId id = msg.readBeingId("item object id"); const int itemId = msg.readInt16("item id"); const uint8_t identify = msg.readUInt8("identify"); const int x = msg.readInt16("x"); diff --git a/src/net/tmwa/mercenaryhandler.cpp b/src/net/tmwa/mercenaryhandler.cpp index aa71c7f69..7b39823f3 100644 --- a/src/net/tmwa/mercenaryhandler.cpp +++ b/src/net/tmwa/mercenaryhandler.cpp @@ -58,7 +58,7 @@ void MercenaryHandler::move(const int x A_UNUSED, const int y A_UNUSED) const { } -void MercenaryHandler::attack(const int targetId A_UNUSED, +void MercenaryHandler::attack(const BeingId targetId A_UNUSED, const Keep keep A_UNUSED) const { } diff --git a/src/net/tmwa/mercenaryhandler.h b/src/net/tmwa/mercenaryhandler.h index f2fe3ecae..eea2a19a2 100644 --- a/src/net/tmwa/mercenaryhandler.h +++ b/src/net/tmwa/mercenaryhandler.h @@ -48,7 +48,8 @@ class MercenaryHandler final : public MessageHandler, void move(const int x, const int y) const override final; - void attack(const int targetId, const Keep keep) const override final; + void attack(const BeingId targetId, + const Keep keep) const override final; void talk(const std::string &restrict text) const override final; diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index b200729f6..3bb66c6f2 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -105,6 +105,11 @@ int32_t MessageIn::readInt32(const char *const str) return value; } +BeingId MessageIn::readBeingId(const char *const str) +{ + return fromInt(readInt32(str), BeingId); +} + int64_t MessageIn::readInt64(const char *const str) { int64_t value = -1; diff --git a/src/net/tmwa/messagein.h b/src/net/tmwa/messagein.h index ef542bab2..7d27b1188 100644 --- a/src/net/tmwa/messagein.h +++ b/src/net/tmwa/messagein.h @@ -54,6 +54,8 @@ class MessageIn final : public Net::MessageIn int64_t readInt64(const char *const str) override final; + BeingId readBeingId(const char *const str) override final; + uint16_t readId(); }; diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp index 66379ffda..c0cc0321d 100644 --- a/src/net/tmwa/messageout.cpp +++ b/src/net/tmwa/messageout.cpp @@ -83,6 +83,11 @@ void MessageOut::writeInt32(const int32_t value, const char *const str) PacketCounters::incOutBytes(4); } +void MessageOut::writeBeingId(const BeingId value, const char *const str) +{ + writeInt32(toInt(value, int32_t), str); +} + #define LOBYTE(w) (static_cast<unsigned char>(w)) #define HIBYTE(w) (static_cast<unsigned char>(( \ static_cast<uint16_t>(w)) >> 8U)) diff --git a/src/net/tmwa/messageout.h b/src/net/tmwa/messageout.h index c6aa522cc..c83643c38 100644 --- a/src/net/tmwa/messageout.h +++ b/src/net/tmwa/messageout.h @@ -56,6 +56,9 @@ class MessageOut final : public Net::MessageOut void writeInt32(const int32_t value, const char *const str) override final; + void writeBeingId(const BeingId value, + const char *const str) override final; + /** * Encodes coordinates and direction in 3 bytes. */ diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index 3fd1fed60..b3187687c 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -106,23 +106,23 @@ void NpcHandler::handleMessage(Net::MessageIn &msg) BLOCK_END("NpcHandler::handleMessage") } -void NpcHandler::talk(const int npcId) const +void NpcHandler::talk(const BeingId npcId) const { createOutPacket(CMSG_NPC_TALK); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); outMsg.writeInt8(0, "unused"); } -void NpcHandler::nextDialog(const int npcId) const +void NpcHandler::nextDialog(const BeingId npcId) const { createOutPacket(CMSG_NPC_NEXT_REQUEST); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); } -void NpcHandler::closeDialog(const int npcId) +void NpcHandler::closeDialog(const BeingId npcId) { createOutPacket(CMSG_NPC_CLOSE); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); const NpcDialogs::iterator it = NpcDialog::mNpcDialogs.find(npcId); if (it != NpcDialog::mNpcDialogs.end()) @@ -136,45 +136,50 @@ void NpcHandler::closeDialog(const int npcId) } } -void NpcHandler::listInput(const int npcId, const unsigned char value) const +void NpcHandler::listInput(const BeingId npcId, + const unsigned char value) const { createOutPacket(CMSG_NPC_LIST_CHOICE); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); outMsg.writeInt8(value, "value"); } -void NpcHandler::integerInput(const int npcId, const int value) const +void NpcHandler::integerInput(const BeingId npcId, + const int value) const { createOutPacket(CMSG_NPC_INT_RESPONSE); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); outMsg.writeInt32(value, "value"); } -void NpcHandler::stringInput(const int npcId, const std::string &value) const +void NpcHandler::stringInput(const BeingId npcId, + const std::string &value) const { createOutPacket(CMSG_NPC_STR_RESPONSE); outMsg.writeInt16(static_cast<int16_t>(value.length() + 9), "len"); - outMsg.writeInt32(npcId, "npc id"); + outMsg.writeBeingId(npcId, "npc id"); outMsg.writeString(value, static_cast<int>(value.length()), "value"); outMsg.writeInt8(0, "null byte"); } -void NpcHandler::buy(const int beingId) const +void NpcHandler::buy(const BeingId beingId) const { createOutPacket(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(beingId, "npc id"); + outMsg.writeBeingId(beingId, "npc id"); outMsg.writeInt8(0, "action"); } -void NpcHandler::sell(const int beingId) const +void NpcHandler::sell(const BeingId beingId) const { createOutPacket(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(beingId, "npc id"); + outMsg.writeBeingId(beingId, "npc id"); outMsg.writeInt8(1, "action"); } -void NpcHandler::buyItem(const int beingId A_UNUSED, const int itemId, - const unsigned char color, const int amount) const +void NpcHandler::buyItem(const BeingId beingId A_UNUSED, + const int itemId, + const unsigned char color, + const int amount) const { createOutPacket(CMSG_NPC_BUY_REQUEST); if (serverFeatures->haveItemColors()) @@ -193,7 +198,7 @@ void NpcHandler::buyItem(const int beingId A_UNUSED, const int itemId, } } -void NpcHandler::sellItem(const int beingId A_UNUSED, +void NpcHandler::sellItem(const BeingId beingId A_UNUSED, const int itemId, const int amount) const { @@ -242,7 +247,7 @@ void NpcHandler::selectAutoSpell(const int skillId A_UNUSED) const { } -int NpcHandler::getNpc(Net::MessageIn &msg) +BeingId NpcHandler::getNpc(Net::MessageIn &msg) { if (msg.getId() == SMSG_NPC_CHOICE || msg.getId() == SMSG_NPC_MESSAGE @@ -251,7 +256,7 @@ int NpcHandler::getNpc(Net::MessageIn &msg) msg.readInt16("len"); } - const int npcId = msg.readInt32("npc id"); + const BeingId npcId = msg.readBeingId("npc id"); const NpcDialogs::const_iterator diag = NpcDialog::mNpcDialogs.find(npcId); mDialog = nullptr; diff --git a/src/net/tmwa/npchandler.h b/src/net/tmwa/npchandler.h index f8baff5d3..c4880ac15 100644 --- a/src/net/tmwa/npchandler.h +++ b/src/net/tmwa/npchandler.h @@ -39,35 +39,37 @@ class NpcHandler final : public MessageHandler, public Ea::NpcHandler void handleMessage(Net::MessageIn &msg) override final; - void talk(const int npcId) const override final; + void talk(const BeingId npcId) const override final; - void nextDialog(const int npcId) const override final; + void nextDialog(const BeingId npcId) const override final; - void closeDialog(const int npcId) override final; + void closeDialog(const BeingId npcId) override final; - void listInput(const int npcId, + void listInput(const BeingId npcId, const unsigned char value) const override final; - void integerInput(const int npcId, + void integerInput(const BeingId npcId, const int value) const override final; - void stringInput(const int npcId, + void stringInput(const BeingId npcId, const std::string &value) const override final; - void buy(const int beingId) const override final; + void buy(const BeingId beingId) const override final; - void sell(const int beingId) const override final; + void sell(const BeingId beingId) const override final; - void buyItem(const int beingId, const int itemId, + void buyItem(const BeingId beingId, + const int itemId, const unsigned char color, const int amount) const override final; - void sellItem(const int beingId, const int itemId, + void sellItem(const BeingId beingId, + const int itemId, const int amount) const override final; void completeProgressBar() const override final; - int getNpc(Net::MessageIn &msg) override final; + BeingId getNpc(Net::MessageIn &msg) override final; void produceMix(const int nameId, const int materialId1, diff --git a/src/net/tmwa/partyhandler.cpp b/src/net/tmwa/partyhandler.cpp index 6f8787be4..8bb143d75 100644 --- a/src/net/tmwa/partyhandler.cpp +++ b/src/net/tmwa/partyhandler.cpp @@ -128,7 +128,7 @@ void PartyHandler::invite(const std::string &name) const if (being) { createOutPacket(CMSG_PARTY_INVITE); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); } } @@ -139,7 +139,7 @@ void PartyHandler::inviteResponse(const std::string &inviter A_UNUSED, if (localPlayer) { createOutPacket(CMSG_PARTY_INVITED); - outMsg.writeInt32(localPlayer->getId(), "account id"); + outMsg.writeBeingId(localPlayer->getId(), "account id"); outMsg.writeInt32(accept ? 1 : 0, "accept"); } } @@ -154,7 +154,7 @@ void PartyHandler::kick(const Being *const being) const if (being) { createOutPacket(CMSG_PARTY_KICK); - outMsg.writeInt32(being->getId(), "account id"); + outMsg.writeBeingId(being->getId(), "account id"); outMsg.writeString("", 24, "unused"); } } @@ -172,7 +172,7 @@ void PartyHandler::kick(const std::string &name) const } createOutPacket(CMSG_PARTY_KICK); - outMsg.writeInt32(m->getID(), "member id"); + outMsg.writeBeingId(m->getID(), "member id"); outMsg.writeString(name, 24, "unused"); } @@ -265,7 +265,7 @@ void PartyHandler::processPartyInfo(Net::MessageIn &msg) for (int i = 0; i < count; i++) { - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("id"); std::string nick = msg.readString(24, "nick"); std::string map = msg.readString(16, "map"); const bool leader = msg.readUInt8("leader") == 0U; @@ -329,7 +329,7 @@ void PartyHandler::processPartyMessage(Net::MessageIn &msg) if (msgLength <= 0) return; - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("id"); const std::string chatMsg = msg.readString(msgLength, "message"); if (Ea::taParty && partyTab) @@ -386,7 +386,7 @@ void PartyHandler::allowInvite(const bool allow A_UNUSED) const void PartyHandler::processPartyInvited(Net::MessageIn &msg) { - const int id = msg.readInt32("account id"); + const BeingId id = msg.readBeingId("account id"); const std::string partyName = msg.readString(24, "party name"); std::string nick; @@ -406,7 +406,7 @@ void PartyHandler::processPartyInvited(Net::MessageIn &msg) void PartyHandler::processPartyMove(Net::MessageIn &msg) { - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("id"); PartyMember *m = nullptr; if (Ea::taParty) m = Ea::taParty->getMember(id); @@ -437,7 +437,7 @@ void PartyHandler::processPartyMove(Net::MessageIn &msg) void PartyHandler::processPartyUpdateHp(Net::MessageIn &msg) { - const int id = msg.readInt32("id"); + const BeingId id = msg.readBeingId("id"); const int hp = msg.readInt16("hp"); const int maxhp = msg.readInt16("max hp"); PartyMember *m = nullptr; diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index c78382f27..95b157c00 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -124,10 +124,11 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) BLOCK_END("PlayerHandler::handleMessage") } -void PlayerHandler::attack(const int id, const Keep keep) const +void PlayerHandler::attack(const BeingId id, + const Keep keep) const { createOutPacket(CMSG_PLAYER_CHANGE_ACT); - outMsg.writeInt32(id, "target id"); + outMsg.writeBeingId(id, "target id"); if (keep == Keep_true) outMsg.writeInt8(7, "action"); else @@ -170,7 +171,7 @@ void PlayerHandler::pickUp(const FloorItem *const floorItem) const return; createOutPacket(CMSG_ITEM_PICKUP); - outMsg.writeInt32(floorItem->getId(), "object id"); + outMsg.writeBeingId(floorItem->getId(), "object id"); TmwAthena::InventoryHandler *const handler = static_cast<TmwAthena::InventoryHandler*>(inventoryHandler); if (handler) diff --git a/src/net/tmwa/playerhandler.h b/src/net/tmwa/playerhandler.h index f0162c8f2..d8f159e8b 100644 --- a/src/net/tmwa/playerhandler.h +++ b/src/net/tmwa/playerhandler.h @@ -39,7 +39,8 @@ class PlayerHandler final : public MessageHandler, public Ea::PlayerHandler void handleMessage(Net::MessageIn &msg) override final; - void attack(const int id, const Keep keep) const override final; + void attack(const BeingId id, + const Keep keep) const override final; void stopAttack() const override final; void emote(const uint8_t emoteId) const override final; diff --git a/src/net/tmwa/skillhandler.cpp b/src/net/tmwa/skillhandler.cpp index 1b8678682..5e8dd9729 100644 --- a/src/net/tmwa/skillhandler.cpp +++ b/src/net/tmwa/skillhandler.cpp @@ -82,12 +82,12 @@ void SkillHandler::handleMessage(Net::MessageIn &msg) } void SkillHandler::useBeing(const int id, const int level, - const int beingId) const + const BeingId beingId) const { createOutPacket(CMSG_SKILL_USE_BEING); outMsg.writeInt16(static_cast<int16_t>(id), "skill id"); outMsg.writeInt16(static_cast<int16_t>(level), "level"); - outMsg.writeInt32(beingId, "target id"); + outMsg.writeBeingId(beingId, "target id"); } void SkillHandler::usePos(const int id, const int level, diff --git a/src/net/tmwa/skillhandler.h b/src/net/tmwa/skillhandler.h index 047ae6330..62bab67d4 100644 --- a/src/net/tmwa/skillhandler.h +++ b/src/net/tmwa/skillhandler.h @@ -39,13 +39,16 @@ class SkillHandler final : public MessageHandler, public Ea::SkillHandler void handleMessage(Net::MessageIn &msg) override final; - void useBeing(const int id, const int level, - const int beingId) const override final; + void useBeing(const int id, + const int level, + const BeingId beingId) const override final; - void usePos(const int id, const int level, + void usePos(const int id, + const int level, const int x, const int y) const override final; - void usePos(const int id, const int level, + void usePos(const int id, + const int level, const int x, const int y, const std::string &text) const override final; diff --git a/src/net/tmwa/tradehandler.cpp b/src/net/tmwa/tradehandler.cpp index 5962ff89a..4ad803640 100644 --- a/src/net/tmwa/tradehandler.cpp +++ b/src/net/tmwa/tradehandler.cpp @@ -118,7 +118,7 @@ void TradeHandler::request(const Being *const being) const return; createOutPacket(CMSG_TRADE_REQUEST); - outMsg.writeInt32(being->getId(), "player id"); + outMsg.writeBeingId(being->getId(), "player id"); } void TradeHandler::respond(const bool accept) const diff --git a/src/party.cpp b/src/party.cpp index 33722044f..6ca3ae1db 100644 --- a/src/party.cpp +++ b/src/party.cpp @@ -57,7 +57,8 @@ namespace } partySorter; } // namespace -PartyMember::PartyMember(Party *const party, const int id, +PartyMember::PartyMember(Party *const party, + const BeingId id, const std::string &name) : Avatar(name), mParty(party), @@ -82,7 +83,8 @@ Party::~Party() clearMembers(); } -PartyMember *Party::addMember(const int id, const std::string &name) +PartyMember *Party::addMember(const BeingId id, + const std::string &name) { PartyMember *m = getMember(id); if (m) @@ -95,7 +97,7 @@ PartyMember *Party::addMember(const int id, const std::string &name) return m; } -PartyMember *Party::getMember(const int id) const +PartyMember *Party::getMember(const BeingId id) const { MemberList::const_iterator itr = mMembers.begin(); const MemberList::const_iterator itr_end = mMembers.end(); @@ -151,7 +153,7 @@ void Party::removeMember(const PartyMember *const member) } } -void Party::removeMember(const int id) +void Party::removeMember(const BeingId id) { bool deleted = true; while (deleted) @@ -247,7 +249,7 @@ bool Party::isMember(const PartyMember *const member) const return false; } -bool Party::isMember(const int id) const +bool Party::isMember(const BeingId id) const { MemberList::const_iterator itr = mMembers.begin(); const MemberList::const_iterator itr_end = mMembers.end(); diff --git a/src/party.h b/src/party.h index 95b048787..47d84cf45 100644 --- a/src/party.h +++ b/src/party.h @@ -49,7 +49,9 @@ class PartyMember final : public Avatar protected: friend class Party; - PartyMember(Party *const party, const int id, const std::string &name); + PartyMember(Party *const party, + const BeingId id, + const std::string &name); Party *mParty; bool mLeader; @@ -69,14 +71,15 @@ class Party final : public AvatarListModel /** * Adds member to the list. */ - PartyMember *addMember(const int id, const std::string &name); + PartyMember *addMember(const BeingId id, + const std::string &name); /** * Find a member by ID. * * @return the member with the given ID, or NULL if they don't exist. */ - PartyMember *getMember(const int id) const A_WARN_UNUSED; + PartyMember *getMember(const BeingId id) const A_WARN_UNUSED; /** * Find a member by name. @@ -107,7 +110,7 @@ class Party final : public AvatarListModel /** * Removes a member from the party. */ - void removeMember(const int id); + void removeMember(const BeingId id); /** * Removes a member from the party. @@ -139,7 +142,7 @@ class Party final : public AvatarListModel bool isMember(const PartyMember *const member) const A_WARN_UNUSED; - bool isMember(const int id) const A_WARN_UNUSED; + bool isMember(const BeingId id) const A_WARN_UNUSED; bool isMember(const std::string &name) const A_WARN_UNUSED; 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 diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp index 4b627ffde..90494a7d1 100644 --- a/src/spellmanager.cpp +++ b/src/spellmanager.cpp @@ -198,7 +198,7 @@ std::string SpellManager::parseCommand(std::string command, { name = target->getName(); name2 = name; - id = toString(target->getId()); + id = toString(toInt(target->getId(), int)); } else { |