summaryrefslogtreecommitdiff
path: root/src/being
diff options
context:
space:
mode:
Diffstat (limited to 'src/being')
-rw-r--r--src/being/being.cpp85
-rw-r--r--src/being/being.h14
2 files changed, 99 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);
+ }
+ }
+ }
+}
diff --git a/src/being/being.h b/src/being/being.h
index 313a92c2d..a2316d607 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -53,6 +53,8 @@ class Party;
class SpeechBubble;
class Text;
+struct ParticleInfo;
+
extern volatile int cur_time;
enum Gender
@@ -903,6 +905,8 @@ class Being : public ActorSprite, public ConfigListener
void setMap(Map *const map);
+ void recreateItemParticles();
+
protected:
/**
* Updates name's location.
@@ -911,6 +915,12 @@ class Being : public ActorSprite, public ConfigListener
void showName();
+ void addItemParticles(const int id, const SpriteDisplay &display);
+
+ void removeAllItemsParticles();
+
+ void removeItemParticles(const int id);
+
static int getDefaultEffectId(const int type);
BeingInfo *mInfo;
@@ -942,9 +952,13 @@ class Being : public ActorSprite, public ConfigListener
Vector mDest; /**< destination coordinates. */
+ typedef std::map<int, ParticleInfo*> SpriteParticleInfo;
+ typedef SpriteParticleInfo::iterator SpriteParticleInfoIter;
+
StringVect mSpriteColors;
std::vector<int> mSpriteIDs;
std::vector<int> mSpriteColorsIds;
+ SpriteParticleInfo mSpriteParticles;
// Character guild information
std::map<int, Guild*> mGuilds;