summaryrefslogtreecommitdiff
path: root/src/being
diff options
context:
space:
mode:
Diffstat (limited to 'src/being')
-rw-r--r--src/being/being.cpp95
-rw-r--r--src/being/being.h18
2 files changed, 83 insertions, 30 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 5d4e741c4..399b3883c 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -151,7 +151,7 @@ Being::Being(const int id, const Type type, const uint16_t subtype,
mSpriteHide(new int[20]),
mSpriteDraw(new int[20]),
mComment(),
- mPet(nullptr),
+ mPets(),
mOwner(nullptr),
mSpecialParticle(nullptr),
mX(0),
@@ -176,7 +176,6 @@ Being::Being(const int id, const Type type, const uint16_t subtype,
mCriticalHit(0),
mPvpRank(0),
mNumber(100),
- mPetId(0),
mLook(0),
mHairColor(0),
mErased(false),
@@ -242,14 +241,18 @@ Being::~Being()
mAnimationEffect = nullptr;
if (mOwner)
- mOwner->setPet(nullptr);
- if (mPet)
+ mOwner->unassignPet(this);
+ FOR_EACH (std::vector<Being*>::iterator, it, mPets)
{
- mPet->setOwner(nullptr);
- actorManager->erase(mPet);
- delete mPet;
- mPet = nullptr;
+ Being *pet = *it;
+ if (pet)
+ {
+ pet->setOwner(nullptr);
+ actorManager->erase(pet);
+ delete pet;
+ }
}
+ mPets.clear();
removeAllItemsParticles();
}
@@ -1609,8 +1612,12 @@ void Being::logic()
actorManager->destroy(this);
}
- if (mPet)
- mPet->petLogic();
+ FOR_EACH (std::vector<Being*>::iterator, it, mPets)
+ {
+ Being *const pet = *it;
+ if (pet)
+ pet->petLogic();
+ }
const SoundInfo *const sound = mNextSound.sound;
if (sound)
@@ -2121,11 +2128,11 @@ void Being::setSprite(const unsigned int slot, const int id,
if (id1)
{
const ItemInfo &info = ItemDB::get(id1);
- if (mMap)
+ if (mMap && mType == PLAYER)
{
const int pet = info.getPet();
if (pet)
- removePet();
+ removePet(pet);
}
removeItemParticles(id1);
}
@@ -3207,14 +3214,15 @@ void Being::addPet(const int id)
if (!actorManager || !config.getBoolValue("usepets"))
return;
- removePet();
+ if (findChildPet(id))
+ return;
+
Being *const being = actorManager->createBeing(
id, ActorSprite::PET, 0);
if (being)
{
being->setOwner(this);
- mPetId = id;
- mPet = being;
+ mPets.push_back(being);
int dstX = mX;
int dstY = mY;
being->fixPetSpawnPos(dstX, dstY);
@@ -3223,24 +3231,53 @@ void Being::addPet(const int id)
}
}
-void Being::removePet()
+Being *Being::findChildPet(const int id)
+{
+ FOR_EACH (std::vector<Being*>::iterator, it, mPets)
+ {
+ Being *const pet = *it;
+ if (pet && pet->mId == id)
+ return pet;
+ }
+ return nullptr;
+}
+
+void Being::removePet(const int id)
{
if (!actorManager)
return;
- mPetId = 0;
- if (mPet)
+ FOR_EACH (std::vector<Being*>::iterator, it, mPets)
{
- mPet->setOwner(nullptr);
- actorManager->erase(mPet);
- delete mPet;
- mPet = nullptr;
+ Being *const pet = *it;
+ if (pet && pet->mId == id)
+ {
+ pet->setOwner(nullptr);
+ actorManager->erase(pet);
+ mPets.erase(it);
+ delete pet;
+ }
}
}
+void Being::removeAllPets()
+{
+ FOR_EACH (std::vector<Being*>::iterator, it, mPets)
+ {
+ Being *const pet = *it;
+ if (pet)
+ {
+ pet->setOwner(nullptr);
+ actorManager->erase(pet);
+ delete pet;
+ }
+ }
+ mPets.clear();
+}
+
void Being::updatePets()
{
- removePet();
+ removeAllPets();
FOR_EACH (std::vector<int>::const_iterator, it, mSpriteIDs)
{
const int id = *it;
@@ -3249,8 +3286,18 @@ void Being::updatePets()
const ItemInfo &info = ItemDB::get(id);
const int pet = info.getPet();
if (pet)
- {
addPet(pet);
+ }
+}
+
+void Being::unassignPet(Being *const pet1)
+{
+ FOR_EACH (std::vector<Being*>::iterator, it, mPets)
+ {
+ Being *const pet = *it;
+ if (pet == pet1)
+ {
+ mPets.erase(it);
return;
}
}
diff --git a/src/being/being.h b/src/being/being.h
index 634c26d23..a93d0e3db 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -877,21 +877,27 @@ class Being : public ActorSprite, public ConfigListener
void addPet(const int id);
- void removePet();
+ void removePet(const int id);
void updatePets();
void fixPetSpawnPos(int &dstX, int &dstY) const;
- Being *getPet()
- { return mPet; }
+ const std::vector<Being*> &getPets() const
+ { return mPets; }
- void setPet(Being *const pet)
- { mPet = pet; }
+ Being *getFirstPet()
+ { return mPets.empty() ? nullptr : mPets[0]; }
void setOwner(Being *const owner)
{ mOwner = owner; }
+ void unassignPet(Being *const pet);
+
+ void removeAllPets();
+
+ Being *findChildPet(const int id);
+
void playSfx(const SoundInfo &sound, Being *const being,
const bool main, const int x, const int y) const;
@@ -1029,7 +1035,7 @@ class Being : public ActorSprite, public ConfigListener
int *mSpriteHide;
int *mSpriteDraw;
std::string mComment;
- Being *mPet;
+ std::vector<Being*> mPets;
Being *mOwner;
Particle *mSpecialParticle;