~ubuntu-branches/ubuntu/trusty/manaplus/trusty

« back to all changes in this revision

Viewing changes to src/being/being.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-12-02 13:52:14 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20131202135214-75nrorshqrxju2av
Tags: 1.3.11.24-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "being/playerrelations.h"
38
38
 
39
39
#include "particle/particle.h"
 
40
#include "particle/particleinfo.h"
40
41
 
41
42
#include "gui/sdlfont.h"
42
43
 
123
124
    mSpriteColors(),
124
125
    mSpriteIDs(),
125
126
    mSpriteColorsIds(),
 
127
    mSpriteParticles(),
126
128
    mGuilds(),
127
129
    mParty(nullptr),
128
130
    mActionTime(0),
238
240
        mOwner->setPet(nullptr);
239
241
    if (mPet)
240
242
        mPet->setOwner(nullptr);
 
243
 
 
244
    removeAllItemsParticles();
241
245
}
242
246
 
243
247
void Being::setSubtype(const uint16_t subtype, const uint8_t look)
414
418
    if (!userPalette)
415
419
        return;
416
420
 
417
 
    if (!channel.empty() && (langChatTab && langChatTab->getChannelName()
 
421
    if (!channel.empty() && (!langChatTab || langChatTab->getChannelName()
418
422
        != channel))
419
423
    {
420
424
        return;
1917
1921
    if (slot >= mSpriteColorsIds.size())
1918
1922
        mSpriteColorsIds.resize(slot + 1, 1);
1919
1923
 
 
1924
    // here probably need more complex condition
 
1925
    if (slot && mSpriteIDs[slot] == id)
 
1926
        return;
 
1927
 
1920
1928
    // id = 0 means unequip
1921
1929
    if (id == 0)
1922
1930
    {
1934
1942
                if (pet)
1935
1943
                    removePet();
1936
1944
            }
 
1945
            removeItemParticles(id1);
1937
1946
        }
1938
1947
    }
1939
1948
    else
1964
1973
 
1965
1974
        CompoundSprite::setSprite(slot, equipmentSprite);
1966
1975
 
 
1976
        addItemParticles(id, info.getDisplay());
 
1977
 
1967
1978
        if (isWeapon)
1968
1979
            mEquippedWeapon = &ItemDB::get(id);
1969
1980
 
3092
3103
    if (mMap)
3093
3104
        mOffsetY = mMap->getHeightOffset(mX, mY);
3094
3105
}
 
3106
 
 
3107
void Being::removeAllItemsParticles()
 
3108
{
 
3109
    FOR_EACH (SpriteParticleInfoIter, it, mSpriteParticles)
 
3110
    {
 
3111
        delete (*it).second;
 
3112
    }
 
3113
    mSpriteParticles.clear();
 
3114
}
 
3115
 
 
3116
void Being::addItemParticles(const int id, const SpriteDisplay &display)
 
3117
{
 
3118
    SpriteParticleInfoIter it = mSpriteParticles.find(id);
 
3119
    ParticleInfo *pi = nullptr;
 
3120
    if (it == mSpriteParticles.end())
 
3121
    {
 
3122
        pi = new ParticleInfo();
 
3123
        mSpriteParticles[id] = pi;
 
3124
    }
 
3125
    else
 
3126
    {
 
3127
        pi = (*it).second;
 
3128
    }
 
3129
 
 
3130
    if (!pi->particles.empty())
 
3131
        return;
 
3132
 
 
3133
    // setup particle effects
 
3134
    if (Particle::enabled && particleEngine)
 
3135
    {
 
3136
        FOR_EACH (StringVectCIter, itr, display.particles)
 
3137
        {
 
3138
            Particle *const p = particleEngine->addEffect(*itr, 0, 0);
 
3139
            controlParticle(p);
 
3140
            pi->files.push_back(*itr);
 
3141
            pi->particles.push_back(p);
 
3142
        }
 
3143
    }
 
3144
    else
 
3145
    {
 
3146
        FOR_EACH (StringVectCIter, itr, display.particles)
 
3147
            pi->files.push_back(*itr);
 
3148
    }
 
3149
}
 
3150
 
 
3151
void Being::removeItemParticles(const int id)
 
3152
{
 
3153
    SpriteParticleInfoIter it = mSpriteParticles.find(id);
 
3154
    if (it == mSpriteParticles.end())
 
3155
        return;
 
3156
    ParticleInfo *const pi = (*it).second;
 
3157
    if (pi)
 
3158
    {
 
3159
        FOR_EACH (std::vector<Particle*>::const_iterator, itp, pi->particles)
 
3160
            mChildParticleEffects.removeLocally(*itp);
 
3161
        delete pi;
 
3162
    }
 
3163
    mSpriteParticles.erase(it);
 
3164
}
 
3165
 
 
3166
void Being::recreateItemParticles()
 
3167
{
 
3168
    FOR_EACH (SpriteParticleInfoIter, it, mSpriteParticles)
 
3169
    {
 
3170
        ParticleInfo *const pi = (*it).second;
 
3171
        if (pi && !pi->files.empty())
 
3172
        {
 
3173
            FOR_EACH (std::vector<Particle*>::const_iterator,
 
3174
                      itp, pi->particles)
 
3175
            {
 
3176
                mChildParticleEffects.removeLocally(*itp);
 
3177
            }
 
3178
 
 
3179
            FOR_EACH (std::vector<std::string>::const_iterator, str, pi->files)
 
3180
            {
 
3181
                Particle *const p = particleEngine->addEffect(*str, 0, 0);
 
3182
                controlParticle(p);
 
3183
                pi->particles.push_back(p);
 
3184
            }
 
3185
        }
 
3186
    }
 
3187
}