summaryrefslogtreecommitdiff
path: root/src/being
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-05-29 14:30:20 +0300
committerAndrei Karas <akaras@inbox.ru>2015-05-29 14:30:20 +0300
commit0f9ec2061c4ad6157c3186f1cab9c4d8558980b5 (patch)
tree6259593b8436178ad8d981a96a8fd71eab9e04cc /src/being
parent01773c71a4698c6f01fe70d864f922bda65506cb (diff)
downloadplus-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.tar.gz
plus-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.tar.bz2
plus-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.tar.xz
plus-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.zip
Add strong typed int type BeingId.
Diffstat (limited to 'src/being')
-rw-r--r--src/being/actorsprite.cpp2
-rw-r--r--src/being/actorsprite.h9
-rw-r--r--src/being/being.cpp44
-rw-r--r--src/being/being.h16
-rw-r--r--src/being/beingcacheentry.h10
-rw-r--r--src/being/homunculusinfo.h6
-rw-r--r--src/being/localplayer.cpp21
-rw-r--r--src/being/localplayer.h10
-rw-r--r--src/being/mercenaryinfo.h5
-rw-r--r--src/being/petinfo.h6
-rw-r--r--src/being/playerinfo.cpp21
-rw-r--r--src/being/playerinfo.h10
12 files changed, 90 insertions, 70 deletions
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();