summaryrefslogtreecommitdiff
path: root/src/being
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-01-11 23:00:47 +0300
committerAndrei Karas <akaras@inbox.ru>2014-01-11 23:00:47 +0300
commit0fa192854595ebe03cce54ad2b251abc4c8e8827 (patch)
treeb0129f65bc0a70926adea202756d0794db974980 /src/being
parentf9209b4a764e85a7ae0e40eee654b543d2ccf2ae (diff)
downloadmv-0fa192854595ebe03cce54ad2b251abc4c8e8827.tar.gz
mv-0fa192854595ebe03cce54ad2b251abc4c8e8827.tar.bz2
mv-0fa192854595ebe03cce54ad2b251abc4c8e8827.tar.xz
mv-0fa192854595ebe03cce54ad2b251abc4c8e8827.zip
add support for multiply pets for one player at same time.
But one item still can have only one pet.
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;