summaryrefslogtreecommitdiff
path: root/src/being/being.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-11-10 14:53:33 +0300
committerAndrei Karas <akaras@inbox.ru>2013-11-10 15:41:25 +0300
commit44e5d8bcb7fea443ca9ed3844454b11ac6e4dbed (patch)
tree1af016870cd47c00e860673d1710b0b98a3bf101 /src/being/being.cpp
parente5f83f094dd658163150ea2a41c5d4a67f21019c (diff)
downloadmv-44e5d8bcb7fea443ca9ed3844454b11ac6e4dbed.tar.gz
mv-44e5d8bcb7fea443ca9ed3844454b11ac6e4dbed.tar.bz2
mv-44e5d8bcb7fea443ca9ed3844454b11ac6e4dbed.tar.xz
mv-44e5d8bcb7fea443ca9ed3844454b11ac6e4dbed.zip
add support for item particles.
For this used particlefx tag in items.xml
Diffstat (limited to 'src/being/being.cpp')
-rw-r--r--src/being/being.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp
index cda6557e4..f28ea591b 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -37,6 +37,7 @@
#include "being/playerrelations.h"
#include "particle/particle.h"
+#include "particle/particleinfo.h"
#include "gui/sdlfont.h"
@@ -238,6 +239,8 @@ Being::~Being()
mOwner->setPet(nullptr);
if (mPet)
mPet->setOwner(nullptr);
+
+ removeAllItemsParticles();
}
void Being::setSubtype(const uint16_t subtype, const uint8_t look)
@@ -1934,6 +1937,7 @@ void Being::setSprite(const unsigned int slot, const int id,
if (pet)
removePet();
}
+ removeItemParticles(id1);
}
}
else
@@ -1964,6 +1968,8 @@ void Being::setSprite(const unsigned int slot, const int id,
CompoundSprite::setSprite(slot, equipmentSprite);
+ addItemParticles(id, info.getDisplay());
+
if (isWeapon)
mEquippedWeapon = &ItemDB::get(id);
@@ -3092,3 +3098,82 @@ void Being::setMap(Map *const map)
if (mMap)
mOffsetY = mMap->getHeightOffset(mX, mY);
}
+
+void Being::removeAllItemsParticles()
+{
+ FOR_EACH (SpriteParticleInfoIter, it, mSpriteParticles)
+ {
+ delete (*it).second;
+ }
+ mSpriteParticles.clear();
+}
+
+void Being::addItemParticles(const int id, const SpriteDisplay &display)
+{
+ SpriteParticleInfoIter it = mSpriteParticles.find(id);
+ ParticleInfo *pi = nullptr;
+ if (it == mSpriteParticles.end())
+ {
+ pi = new ParticleInfo();
+ mSpriteParticles[id] = pi;
+ }
+ else
+ {
+ pi = (*it).second;
+ }
+
+ if (!pi->particles.empty())
+ return;
+
+ // setup particle effects
+ if (Particle::enabled && particleEngine)
+ {
+ FOR_EACH (StringVectCIter, itr, display.particles)
+ {
+ Particle *const p = particleEngine->addEffect(*itr, 0, 0);
+ controlParticle(p);
+ pi->files.push_back(*itr);
+ pi->particles.push_back(p);
+ }
+ }
+ else
+ {
+ FOR_EACH (StringVectCIter, itr, display.particles)
+ pi->files.push_back(*itr);
+ }
+}
+
+void Being::removeItemParticles(const int id)
+{
+ SpriteParticleInfoIter it = mSpriteParticles.find(id);
+ if (it == mSpriteParticles.end())
+ return;
+ ParticleInfo *const pi = (*it).second;
+ if (pi)
+ {
+ FOR_EACH (std::vector<Particle*>::const_iterator, itp, pi->particles)
+ mChildParticleEffects.removeLocally(*itp);
+ delete pi;
+ }
+ mSpriteParticles.erase(it);
+}
+
+void Being::recreateItemParticles()
+{
+ FOR_EACH (SpriteParticleInfoIter, it, mSpriteParticles)
+ {
+ ParticleInfo *const pi = (*it).second;
+ if (pi && !pi->files.empty())
+ {
+ FOR_EACH (std::vector<Particle*>::const_iterator, itp, pi->particles)
+ mChildParticleEffects.removeLocally(*itp);
+
+ FOR_EACH (std::vector<std::string>::const_iterator, str, pi->files)
+ {
+ Particle *const p = particleEngine->addEffect(*str, 0, 0);
+ controlParticle(p);
+ pi->particles.push_back(p);
+ }
+ }
+ }
+}