diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-09-02 16:21:43 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-09-02 16:35:24 +0300 |
commit | e0ae701192472d7dd1ae80d78308c4f4a9ef4ec6 (patch) | |
tree | 9765a6516e4a6e284ed7b589090db7f1f4cd80ea /src | |
parent | 962f182fcc989ec587282e44f889188ce241ba31 (diff) | |
download | manaverse-e0ae701192472d7dd1ae80d78308c4f4a9ef4ec6.tar.gz manaverse-e0ae701192472d7dd1ae80d78308c4f4a9ef4ec6.tar.bz2 manaverse-e0ae701192472d7dd1ae80d78308c4f4a9ef4ec6.tar.xz manaverse-e0ae701192472d7dd1ae80d78308c4f4a9ef4ec6.zip |
Add const to more classes.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/widgets/avatarlistbox.h | 2 | ||||
-rw-r--r-- | src/particle.cpp | 56 | ||||
-rw-r--r-- | src/particle.h | 54 | ||||
-rw-r--r-- | src/particlecontainer.cpp | 26 | ||||
-rw-r--r-- | src/particlecontainer.h | 25 | ||||
-rw-r--r-- | src/particleemitter.cpp | 78 | ||||
-rw-r--r-- | src/particleemitter.h | 10 | ||||
-rw-r--r-- | src/particleemitterprop.h | 6 | ||||
-rw-r--r-- | src/party.cpp | 64 | ||||
-rw-r--r-- | src/party.h | 24 | ||||
-rw-r--r-- | src/playerinfo.cpp | 68 | ||||
-rw-r--r-- | src/playerinfo.h | 43 | ||||
-rw-r--r-- | src/playerrelations.cpp | 67 | ||||
-rw-r--r-- | src/playerrelations.h | 28 | ||||
-rw-r--r-- | src/position.h | 2 | ||||
-rw-r--r-- | src/properties.h | 12 |
16 files changed, 301 insertions, 264 deletions
diff --git a/src/gui/widgets/avatarlistbox.h b/src/gui/widgets/avatarlistbox.h index 0148a24d0..995ffebe6 100644 --- a/src/gui/widgets/avatarlistbox.h +++ b/src/gui/widgets/avatarlistbox.h @@ -37,7 +37,7 @@ class Image; class AvatarListModel : public gcn::ListModel { public: - virtual Avatar *getAvatarAt(int i) = 0; + virtual Avatar *getAvatarAt(const int i) = 0; std::string getElementAt(int i) { return getAvatarAt(i)->getName(); } diff --git a/src/particle.cpp b/src/particle.cpp index 950411f7b..3e5bda24f 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -57,7 +57,7 @@ int Particle::emitterSkip = 1; bool Particle::enabled = true; const float Particle::PARTICLE_SKY = 800.0f; -Particle::Particle(Map *map): +Particle::Particle(Map *const map) : mAlpha(1.0f), mLifetimeLeft(-1), mLifetimePast(0), @@ -113,7 +113,7 @@ bool Particle::update() if (mLifetimeLeft == 0 && mAlive == ALIVE) mAlive = DEAD_TIMEOUT; - Vector oldPos = mPos; + const Vector oldPos = mPos; if (mAlive == ALIVE) { @@ -152,7 +152,7 @@ bool Particle::update() { if (mInvDieDistance > 0.0f && invHypotenuse > mInvDieDistance) mAlive = DEAD_IMPACT; - float accFactor = invHypotenuse * mAcceleration; + const float accFactor = invHypotenuse * mAcceleration; mVelocity -= dist * accFactor; } } @@ -220,7 +220,7 @@ bool Particle::update() { if ((mAlive & mDeathEffectConditions) > 0x00 && !mDeathEffect.empty()) { - Particle* deathEffect = particleEngine->addEffect( + Particle *const deathEffect = particleEngine->addEffect( mDeathEffect, 0, 0); if (deathEffect) deathEffect->moveBy(mPos); @@ -228,7 +228,7 @@ bool Particle::update() mAlive = DEAD_LONG_AGO; } - Vector change = mPos - oldPos; + const Vector change = mPos - oldPos; // Update child particles @@ -267,20 +267,21 @@ void Particle::moveBy(const Vector &change) } } -void Particle::moveTo(float x, float y) +void Particle::moveTo(const float x, const float y) { moveTo(Vector(x, y, mPos.z)); } Particle *Particle::createChild() { - Particle *newParticle = new Particle(mMap); + Particle *const newParticle = new Particle(mMap); mChildParticles.push_back(newParticle); return newParticle; } Particle *Particle::addEffect(const std::string &particleEffectFile, - int pixelX, int pixelY, int rotation) + const int pixelX, const int pixelY, + const int rotation) { Particle *newParticle = nullptr; @@ -290,7 +291,7 @@ Particle *Particle::addEffect(const std::string &particleEffectFile, dyePalettes = particleEffectFile.substr(pos + 1); XML::Document doc(particleEffectFile.substr(0, pos)); - XmlNodePtr rootNode = doc.rootNode(); + const XmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlNameEqual(rootNode, "effect")) { @@ -298,7 +299,7 @@ Particle *Particle::addEffect(const std::string &particleEffectFile, return nullptr; } - ResourceManager *resman = ResourceManager::getInstance(); + ResourceManager *const resman = ResourceManager::getInstance(); // Parse particles for_each_xml_child_node(effectChildNode, rootNode) @@ -328,7 +329,7 @@ Particle *Particle::addEffect(const std::string &particleEffectFile, node->xmlChildrenNode->content); if (!imageSrc.empty() && !dyePalettes.empty()) Dye::instantiate(imageSrc, dyePalettes); - Image *img = resman->getImage(imageSrc); + Image *const img = resman->getImage(imageSrc); newParticle = new ImageParticle(mMap, img); } @@ -339,20 +340,20 @@ Particle *Particle::addEffect(const std::string &particleEffectFile, } // Read and set the basic properties of the particle - float offsetX = static_cast<float>(XML::getFloatProperty( + const float offsetX = static_cast<float>(XML::getFloatProperty( effectChildNode, "position-x", 0)); - float offsetY = static_cast<float>(XML::getFloatProperty( + const float offsetY = static_cast<float>(XML::getFloatProperty( effectChildNode, "position-y", 0)); - float offsetZ = static_cast<float>(XML::getFloatProperty( + const float offsetZ = static_cast<float>(XML::getFloatProperty( effectChildNode, "position-z", 0)); Vector position (mPos.x + static_cast<float>(pixelX) + offsetX, mPos.y + static_cast<float>(pixelY) + offsetY, mPos.z + offsetZ); newParticle->moveTo(position); - int lifetime = XML::getProperty(effectChildNode, "lifetime", -1); + const int lifetime = XML::getProperty(effectChildNode, "lifetime", -1); newParticle->setLifetime(lifetime); - bool resizeable = "false" != XML::getProperty(effectChildNode, + const bool resizeable = "false" != XML::getProperty(effectChildNode, "size-adjustable", "false"); newParticle->setAllowSizeAdjust(resizeable); @@ -409,11 +410,14 @@ Particle *Particle::addEffect(const std::string &particleEffectFile, return newParticle; } -Particle *Particle::addTextSplashEffect(const std::string &text, int x, int y, - const gcn::Color *color, - gcn::Font *font, bool outline) +Particle *Particle::addTextSplashEffect(const std::string &text, + const int x, const int y, + const gcn::Color *const color, + gcn::Font *const font, + const bool outline) { - Particle *newParticle = new TextParticle(mMap, text, color, font, outline); + Particle *const newParticle = new TextParticle( + mMap, text, color, font, outline); newParticle->moveTo(static_cast<float>(x), static_cast<float>(y)); newParticle->setVelocity( static_cast<float>((rand() % 100) - 50) / 200.0f, // X @@ -431,11 +435,13 @@ Particle *Particle::addTextSplashEffect(const std::string &text, int x, int y, } Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, - int x, int y, - const gcn::Color *color, - gcn::Font *font, bool outline) + const int x, const int y, + const gcn::Color *const color, + gcn::Font *const font, + const bool outline) { - Particle *newParticle = new TextParticle(mMap, text, color, font, outline); + Particle *const newParticle = new TextParticle( + mMap, text, color, font, outline); newParticle->moveTo(static_cast<float>(x), static_cast<float>(y)); newParticle->setVelocity(0.0f, 0.0f, 0.5f); newParticle->setGravity(0.0015f); @@ -448,7 +454,7 @@ Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, return newParticle; } -void Particle::adjustEmitterSize(int w, int h) +void Particle::adjustEmitterSize(const int w, const int h) { if (mAllowSizeAdjust) { diff --git a/src/particle.h b/src/particle.h index ecb3072f8..04a1b3e85 100644 --- a/src/particle.h +++ b/src/particle.h @@ -78,7 +78,7 @@ class Particle : public Actor * * @param map the map this particle will add itself to, may be nullptr */ - Particle(Map *map); + Particle(Map *const map); /** * Destructor. @@ -130,28 +130,31 @@ class Particle : public Actor * particleEffectFile. */ Particle *addEffect(const std::string &particleEffectFile, - int pixelX, int pixelY, int rotation = 0); + const int pixelX, const int pixelY, + const int rotation = 0); /** * Creates a standalone text particle. */ - Particle *addTextSplashEffect(const std::string &text, int x, int y, - const gcn::Color *color, gcn::Font *font, - bool outline = false); + Particle *addTextSplashEffect(const std::string &text, + const int x, const int y, + const gcn::Color *const color, + gcn::Font *const font, + const bool outline = false); /** * Creates a standalone text particle. */ Particle *addTextRiseFadeOutEffect(const std::string &text, - int x, int y, - const gcn::Color *color, - gcn::Font *font, - bool outline = false); + const int x, const int y, + const gcn::Color *const color, + gcn::Font *const font, + const bool outline = false); /** * Adds an emitter to the particle. */ - void addEmitter (ParticleEmitter* emitter) + void addEmitter (ParticleEmitter *const emitter) { mChildEmitters.push_back(emitter); } /** @@ -163,7 +166,7 @@ class Particle : public Actor /** * Sets the position in 2 dimensional space in pixels relative to map. */ - void moveTo(float x, float y); + void moveTo(const float x, const float y); /** * Changes the particle position relative @@ -173,52 +176,52 @@ class Particle : public Actor /** * Sets the time in game ticks until the particle is destroyed. */ - void setLifetime(int lifetime) + void setLifetime(const int lifetime) { mLifetimeLeft = lifetime; mLifetimePast = 0; } /** * Sets the age of the pixel in game ticks where the particle has * faded in completely. */ - void setFadeOut(int fadeOut) + void setFadeOut(const int fadeOut) { mFadeOut = fadeOut; } /** * Sets the remaining particle lifetime where the particle starts to * fade out. */ - void setFadeIn(int fadeIn) + void setFadeIn(const int fadeIn) { mFadeIn = fadeIn; } /** * Sets the current velocity in 3 dimensional space. */ - void setVelocity(float x, float y, float z) + void setVelocity(const float x, const float y, const float z) { mVelocity.x = x; mVelocity.y = y; mVelocity.z = z; } /** * Sets the downward acceleration. */ - void setGravity(float gravity) + void setGravity(const float gravity) { mGravity = gravity; } /** * Sets the ammount of random vector changes */ - void setRandomness(int r) + void setRandomness(const int r) { mRandomness = r; } /** * Sets the ammount of velocity particles retain after * hitting the ground. */ - void setBounce(float bouncieness) + void setBounce(const float bouncieness) { mBounce = bouncieness; } /** * Sets the flag if the particle is supposed to be moved by its parent */ - void setFollow(bool follow) + void setFollow(const bool follow) { mFollow = follow; } /** @@ -231,7 +234,8 @@ class Particle : public Actor * Makes the particle move toward another particle with a * given acceleration and momentum */ - void setDestination(Particle *target, float accel, float moment) + void setDestination(Particle *const target, + const float accel, const float moment) { mTarget = target; mAcceleration = accel; mMomentum = moment; } /** @@ -239,16 +243,16 @@ class Particle : public Actor * particle before it is destroyed. Does only make sense after a target * particle has been set using setDestination. */ - void setDieDistance(float dist) + void setDieDistance(const float dist) { mInvDieDistance = 1.0f / dist; } /** * Changes the size of the emitters so that the effect fills a * rectangle of this size */ - void adjustEmitterSize(int w, int h); + void adjustEmitterSize(const int w, const int h); - void setAllowSizeAdjust(bool adjust) + void setAllowSizeAdjust(const bool adjust) { mAllowSizeAdjust = adjust; } bool isAlive() const @@ -280,11 +284,11 @@ class Particle : public Actor virtual float getAlpha() const { return 1.0f; } - virtual void setAlpha(float alpha A_UNUSED) + virtual void setAlpha(const float alpha A_UNUSED) { } virtual void setDeathEffect(const std::string &effectFile, - char conditions) + const char conditions) { mDeathEffect = effectFile; mDeathEffectConditions = conditions; } protected: diff --git a/src/particlecontainer.cpp b/src/particlecontainer.cpp index 9421e6354..b26457d3b 100644 --- a/src/particlecontainer.cpp +++ b/src/particlecontainer.cpp @@ -25,8 +25,8 @@ #include "debug.h" -ParticleContainer::ParticleContainer(ParticleContainer *parent, - bool delParent): +ParticleContainer::ParticleContainer(ParticleContainer *const parent, + const bool delParent): mDelParent(delParent), mNext(parent) {} @@ -48,7 +48,7 @@ void ParticleContainer::clear() mNext->clear(); } -void ParticleContainer::moveTo(float x, float y) +void ParticleContainer::moveTo(const float x, const float y) { if (mNext) mNext->moveTo(x, y); @@ -56,14 +56,15 @@ void ParticleContainer::moveTo(float x, float y) // -- particle list ---------------------------------------- -ParticleList::ParticleList(ParticleContainer *parent, bool delParent): +ParticleList::ParticleList(ParticleContainer *const parent, + const bool delParent) : ParticleContainer(parent, delParent) {} ParticleList::~ParticleList() {} -void ParticleList::addLocally(Particle *particle) +void ParticleList::addLocally(Particle *const particle) { if (particle) { @@ -73,7 +74,7 @@ void ParticleList::addLocally(Particle *particle) } } -void ParticleList::removeLocally(Particle *particle) +void ParticleList::removeLocally(const Particle *const particle) { for (std::list<Particle *>::iterator it = mElements.begin(); it != mElements.end(); ) @@ -101,7 +102,7 @@ void ParticleList::clearLocally() mElements.clear(); } -void ParticleList::moveTo(float x, float y) +void ParticleList::moveTo(const float x, const float y) { ParticleContainer::moveTo(x, y); @@ -123,14 +124,15 @@ void ParticleList::moveTo(float x, float y) // -- particle vector ---------------------------------------- -ParticleVector::ParticleVector(ParticleContainer *parent, bool delParent): +ParticleVector::ParticleVector(ParticleContainer *const parent, + const bool delParent) : ParticleContainer(parent, delParent) {} ParticleVector::~ParticleVector() {} -void ParticleVector::setLocally(int index, Particle *particle) +void ParticleVector::setLocally(const int index, Particle *const particle) { if (index < 0) return; @@ -145,7 +147,7 @@ void ParticleVector::setLocally(int index, Particle *particle) mIndexedElements[index] = particle; } -void ParticleVector::delLocally(int index) +void ParticleVector::delLocally(const int index) { if (index < 0) return; @@ -153,7 +155,7 @@ void ParticleVector::delLocally(int index) if (mIndexedElements.size() <= static_cast<unsigned>(index)) return; - Particle *p = mIndexedElements[index]; + Particle *const p = mIndexedElements[index]; if (p) { mIndexedElements[index] = nullptr; @@ -167,7 +169,7 @@ void ParticleVector::clearLocally() delLocally(i); } -void ParticleVector::moveTo(float x, float y) +void ParticleVector::moveTo(const float x, const float y) { ParticleContainer::moveTo(x, y); diff --git a/src/particlecontainer.h b/src/particlecontainer.h index 4e402044b..f83b62d1a 100644 --- a/src/particlecontainer.h +++ b/src/particlecontainer.h @@ -44,8 +44,8 @@ public: * * delParent means that the destructor should also free the parent. */ - ParticleContainer(ParticleContainer *parent = nullptr, - bool delParent = true); + ParticleContainer(ParticleContainer *const parent = nullptr, + const bool delParent = true); virtual ~ParticleContainer(); @@ -63,7 +63,7 @@ public: /** * Sets the positions of all elements */ - virtual void moveTo(float x, float y); + virtual void moveTo(const float x, const float y); protected: bool mDelParent; /**< Delete mNext in destructor */ @@ -76,22 +76,23 @@ protected: class ParticleList : public ParticleContainer { public: - ParticleList(ParticleContainer *parent = nullptr, bool delParent = true); + ParticleList(ParticleContainer *const parent = nullptr, + const bool delParent = true); virtual ~ParticleList(); /** * Takes control of and adds a particle */ - void addLocally(Particle *); + void addLocally(Particle *const particle); /** * `kills' and removes a particle */ - void removeLocally(Particle *); + void removeLocally(const Particle *const particle); virtual void clearLocally(); - virtual void moveTo(float x, float y); + virtual void moveTo(const float x, const float y); protected: std::list<Particle *> mElements; /**< Contained particle effects */ @@ -103,22 +104,24 @@ protected: class ParticleVector : public ParticleContainer { public: - ParticleVector(ParticleContainer *parent = nullptr, bool delParent = true); + ParticleVector(ParticleContainer *const parent = nullptr, + const bool delParent = true); + virtual ~ParticleVector(); /** * Sets a particle at a specified index. Kills the previous particle * there, if needed. */ - virtual void setLocally(int index, Particle *particle); + virtual void setLocally(const int index, Particle *const particle); /** * Removes a particle at a specified index */ - virtual void delLocally(int index); + virtual void delLocally(const int index); virtual void clearLocally(); - virtual void moveTo(float x, float y); + virtual void moveTo(const float x, const float y); protected: std::vector<Particle *> mIndexedElements; diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index 9b84a3392..8fbb5eca3 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -38,8 +38,9 @@ static const float SIN45 = 0.707106781f; static const float DEG_RAD_FACTOR = 0.017453293f; -ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target, - Map *map, int rotation, +ParticleEmitter::ParticleEmitter(const XmlNodePtr emitterNode, + Particle *const target, + Map *const map, const int rotation, const std::string& dyePalettes) : mParticleTarget(target), mMap(map), @@ -102,7 +103,8 @@ ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target, if (!dyePalettes.empty()) Dye::instantiate(image, dyePalettes); - ResourceManager *resman = ResourceManager::getInstance(); + ResourceManager *const resman + = ResourceManager::getInstance(); mParticleImage = resman->getImage(image); } } @@ -203,8 +205,8 @@ ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target, } else if (xmlNameEqual(propertyNode, "rotation")) { - ImageSet *imageset = ResourceManager::getInstance()->getImageSet( - XML::getProperty(propertyNode, "imageset", ""), + ImageSet *const imageset = ResourceManager::getInstance() + ->getImageSet(XML::getProperty(propertyNode, "imageset", ""), XML::getProperty(propertyNode, "width", 0), XML::getProperty(propertyNode, "height", 0) ); @@ -219,18 +221,19 @@ ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target, // Get animation frames for_each_xml_child_node(frameNode, propertyNode) { - int delay = XML::getIntProperty( + const int delay = XML::getIntProperty( frameNode, "delay", 0, 0, 100000); int offsetX = XML::getProperty(frameNode, "offsetX", 0); int offsetY = XML::getProperty(frameNode, "offsetY", 0); - int rand = XML::getIntProperty(frameNode, "rand", 100, 0, 100); + const int rand = XML::getIntProperty( + frameNode, "rand", 100, 0, 100); offsetY -= imageset->getHeight() - 32; offsetX -= imageset->getWidth() / 2 - 16; if (xmlNameEqual(frameNode, "frame")) { - int index = XML::getProperty(frameNode, "index", -1); + const int index = XML::getProperty(frameNode, "index", -1); if (index < 0) { @@ -238,7 +241,7 @@ ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target, continue; } - Image *img = imageset->get(index); + Image *const img = imageset->get(index); if (!img) { @@ -252,7 +255,7 @@ ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target, else if (xmlNameEqual(frameNode, "sequence")) { int start = XML::getProperty(frameNode, "start", -1); - int end = XML::getProperty(frameNode, "end", -1); + const int end = XML::getProperty(frameNode, "end", -1); if (start < 0 || end < 0) { @@ -262,7 +265,7 @@ ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target, while (end >= start) { - Image *img = imageset->get(start); + Image *const img = imageset->get(start); if (!img) { @@ -283,8 +286,8 @@ ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target, } else if (xmlNameEqual(propertyNode, "animation")) { - ImageSet *imageset = ResourceManager::getInstance()->getImageSet( - XML::getProperty(propertyNode, "imageset", ""), + ImageSet *const imageset = ResourceManager::getInstance() + ->getImageSet(XML::getProperty(propertyNode, "imageset", ""), XML::getProperty(propertyNode, "width", 0), XML::getProperty(propertyNode, "height", 0) ); @@ -299,17 +302,18 @@ ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target, // Get animation frames for_each_xml_child_node(frameNode, propertyNode) { - int delay = XML::getIntProperty( + const int delay = XML::getIntProperty( frameNode, "delay", 0, 0, 100000); - int offsetX = XML::getProperty(frameNode, "offsetX", 0); - int offsetY = XML::getProperty(frameNode, "offsetY", 0); - int rand = XML::getIntProperty(frameNode, "rand", 100, 0, 100); - offsetY -= imageset->getHeight() - 32; - offsetX -= imageset->getWidth() / 2 - 16; + int offsetX = XML::getProperty(frameNode, "offsetX", 0) + - (imageset->getWidth() / 2 - 16); + int offsetY = XML::getProperty(frameNode, "offsetY", 0) + - (imageset->getHeight() - 32); + const int rand = XML::getIntProperty( + frameNode, "rand", 100, 0, 100); if (xmlNameEqual(frameNode, "frame")) { - int index = XML::getProperty(frameNode, "index", -1); + const int index = XML::getProperty(frameNode, "index", -1); if (index < 0) { @@ -317,7 +321,7 @@ ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target, continue; } - Image *img = imageset->get(index); + Image *const img = imageset->get(index); if (!img) { @@ -331,7 +335,7 @@ ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target, else if (xmlNameEqual(frameNode, "sequence")) { int start = XML::getProperty(frameNode, "start", -1); - int end = XML::getProperty(frameNode, "end", -1); + const int end = XML::getProperty(frameNode, "end", -1); if (start < 0 || end < 0) { @@ -341,7 +345,7 @@ ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target, while (end >= start) { - Image *img = imageset->get(start); + Image *const img = imageset->get(start); if (!img) { @@ -495,7 +499,7 @@ ParticleEmitter::readParticleEmitterProp(XmlNodePtr propertyNode, T def) } -std::list<Particle *> ParticleEmitter::createParticles(int tick) +std::list<Particle *> ParticleEmitter::createParticles(const int tick) { std::list<Particle *> newParticles; @@ -529,12 +533,12 @@ std::list<Particle *> ParticleEmitter::createParticles(int tick) } else if (!mParticleRotation.mFrames.empty()) { - Animation *newAnimation = new Animation(mParticleRotation); + Animation *const newAnimation = new Animation(mParticleRotation); newParticle = new RotationalParticle(mMap, newAnimation); } else if (!mParticleAnimation.mFrames.empty()) { - Animation *newAnimation = new Animation(mParticleAnimation); + Animation *const newAnimation = new Animation(mParticleAnimation); newParticle = new AnimationParticle(mMap, newAnimation); } else @@ -547,9 +551,9 @@ std::list<Particle *> ParticleEmitter::createParticles(int tick) mParticlePosZ.value(tick)); newParticle->moveTo(position); - float angleH = mParticleAngleHorizontal.value(tick); - float angleV = mParticleAngleVertical.value(tick); - float power = mParticlePower.value(tick); + const float angleH = mParticleAngleHorizontal.value(tick); + const float angleV = mParticleAngleVertical.value(tick); + const float power = mParticlePower.value(tick); newParticle->setVelocity( static_cast<float>(cos(angleH) * cos(angleV)) * power, static_cast<float>(sin(angleH) * cos(angleV)) * power, @@ -588,17 +592,17 @@ std::list<Particle *> ParticleEmitter::createParticles(int tick) return newParticles; } -void ParticleEmitter::adjustSize(int w, int h) +void ParticleEmitter::adjustSize(const int w, const int h) { if (w == 0 || h == 0) return; // new dimensions are illegal // calculate the old rectangle - int oldWidth = static_cast<int>(mParticlePosX.maxVal - - mParticlePosX.minVal); - int oldHeight = static_cast<int>(mParticlePosX.maxVal - - mParticlePosY.minVal); - int oldArea = oldWidth * oldHeight; + const int oldWidth = static_cast<int>( + mParticlePosX.maxVal - mParticlePosX.minVal); + const int oldHeight = static_cast<int>( + mParticlePosX.maxVal - mParticlePosY.minVal); + const int oldArea = oldWidth * oldHeight; if (oldArea == 0) { //when the effect has no dimension it is @@ -609,9 +613,9 @@ void ParticleEmitter::adjustSize(int w, int h) // set the new dimensions mParticlePosX.set(0, static_cast<float>(w)); mParticlePosY.set(0, static_cast<float>(h)); - int newArea = w * h; + const int newArea = w * h; // adjust the output so that the particle density stays the same - float outputFactor = static_cast<float>(newArea) + const float outputFactor = static_cast<float>(newArea) / static_cast<float>(oldArea); mOutput.minVal = static_cast<int>(static_cast<float>( mOutput.minVal) * outputFactor); diff --git a/src/particleemitter.h b/src/particleemitter.h index faa54dd12..17d388f82 100644 --- a/src/particleemitter.h +++ b/src/particleemitter.h @@ -43,8 +43,8 @@ class Particle; class ParticleEmitter { public: - ParticleEmitter(XmlNodePtr emitterNode, Particle *target, Map *map, - int rotation = 0, + ParticleEmitter(const XmlNodePtr emitterNode, Particle *const target, + Map *const map, const int rotation = 0, const std::string& dyePalettes = std::string()); /** @@ -66,19 +66,19 @@ class ParticleEmitter * Spawns new particles * @return: a list of created particles */ - std::list<Particle *> createParticles(int tick); + std::list<Particle *> createParticles(const int tick); /** * Sets the target of the particles that are created */ - void setTarget(Particle *target) + void setTarget(Particle *const target) { mParticleTarget = target; }; /** * Changes the size of the emitter so that the effect fills a * rectangle of this size */ - void adjustSize(int w, int h); + void adjustSize(const int w, const int h); private: template <typename T> ParticleEmitterProp<T> diff --git a/src/particleemitterprop.h b/src/particleemitterprop.h index 2b6b7ba1a..354cb0229 100644 --- a/src/particleemitterprop.h +++ b/src/particleemitterprop.h @@ -45,13 +45,13 @@ template <typename T> struct ParticleEmitterProp { } - void set(T min, T max) + void set(const T min, const T max) { minVal = min; maxVal = max; } - void set(T val) + void set(const T val) { set(val, val); } @@ -66,7 +66,7 @@ template <typename T> struct ParticleEmitterProp changePhase = phase; } - T value(int tick) + T value(int tick) const { tick += changePhase; T val = static_cast<T>(minVal + (maxVal - minVal) diff --git a/src/party.cpp b/src/party.cpp index 56c0b0de9..08e9afcd1 100644 --- a/src/party.cpp +++ b/src/party.cpp @@ -30,7 +30,8 @@ class SortPartyFunctor { public: - bool operator() (PartyMember* p1, PartyMember* p2) + bool operator() (const PartyMember *const p1, + const PartyMember *const p2) const { if (!p1 || !p2) return false; @@ -51,7 +52,8 @@ class SortPartyFunctor } } partySorter; -PartyMember::PartyMember(Party *party, int id, const std::string &name): +PartyMember::PartyMember(Party *const party, const int id, + const std::string &name) : Avatar(name), mParty(party), mLeader(false) { mId = id; @@ -59,7 +61,7 @@ PartyMember::PartyMember(Party *party, int id, const std::string &name): Party::PartyMap Party::parties; -Party::Party(short id): +Party::Party(const short id) : mId(id), mCanInviteUsers(false) { @@ -71,7 +73,7 @@ Party::~Party() clearMembers(); } -PartyMember *Party::addMember(int id, const std::string &name) +PartyMember *Party::addMember(const int id, const std::string &name) { PartyMember *m; if ((m = getMember(id))) @@ -84,10 +86,10 @@ PartyMember *Party::addMember(int id, const std::string &name) return m; } -PartyMember *Party::getMember(int id) const +PartyMember *Party::getMember(const int id) const { - MemberList::const_iterator itr = mMembers.begin(), - itr_end = mMembers.end(); + MemberList::const_iterator itr = mMembers.begin(); + const MemberList::const_iterator itr_end = mMembers.end(); while (itr != itr_end) { if ((*itr)->mId == id) @@ -100,8 +102,8 @@ PartyMember *Party::getMember(int id) const PartyMember *Party::getMember(const std::string &name) const { - MemberList::const_iterator itr = mMembers.begin(), - itr_end = mMembers.end(); + MemberList::const_iterator itr = mMembers.begin(); + const MemberList::const_iterator itr_end = mMembers.end(); while (itr != itr_end) { if ((*itr) && (*itr)->getName() == name) @@ -113,7 +115,7 @@ PartyMember *Party::getMember(const std::string &name) const return nullptr; } -void Party::removeMember(PartyMember *member) +void Party::removeMember(const PartyMember *const member) { if (!member) return; @@ -122,8 +124,8 @@ void Party::removeMember(PartyMember *member) while (deleted) { deleted = false; - MemberList::iterator itr = mMembers.begin(), - itr_end = mMembers.end(); + MemberList::iterator itr = mMembers.begin(); + const MemberList::iterator itr_end = mMembers.end(); while (itr != itr_end) { if ((*itr) && (*itr)->mId == member->mId && @@ -140,14 +142,14 @@ void Party::removeMember(PartyMember *member) } } -void Party::removeMember(int id) +void Party::removeMember(const int id) { bool deleted = true; while (deleted) { deleted = false; - MemberList::iterator itr = mMembers.begin(), - itr_end = mMembers.end(); + MemberList::iterator itr = mMembers.begin(); + const MemberList::iterator itr_end = mMembers.end(); while (itr != itr_end) { if ((*itr) && (*itr)->mId == id) @@ -169,8 +171,8 @@ void Party::removeMember(const std::string &name) while (deleted) { deleted = false; - MemberList::iterator itr = mMembers.begin(), - itr_end = mMembers.end(); + MemberList::iterator itr = mMembers.begin(); + const MemberList::iterator itr_end = mMembers.end(); while (itr != itr_end) { if ((*itr) && (*itr)->getName() == name) @@ -192,30 +194,30 @@ void Party::removeFromMembers() return; MemberList::const_iterator itr = mMembers.begin(); - MemberList::const_iterator itr_end = mMembers.end(); + const MemberList::const_iterator itr_end = mMembers.end(); while (itr != itr_end) { - Being *b = actorSpriteManager->findBeing((*itr)->getID()); + Being *const b = actorSpriteManager->findBeing((*itr)->getID()); if (b) b->setParty(nullptr); ++itr; } } -Avatar *Party::getAvatarAt(int index) +Avatar *Party::getAvatarAt(const int index) { return mMembers[index]; } -void Party::setRights(short rights) +void Party::setRights(const short rights) { // to invite, rights must be greater than 0 if (rights > 0) mCanInviteUsers = true; } -bool Party::isMember(PartyMember *member) const +bool Party::isMember(const PartyMember *const member) const { if (!member) return false; @@ -224,7 +226,7 @@ bool Party::isMember(PartyMember *member) const return false; MemberList::const_iterator itr = mMembers.begin(); - MemberList::const_iterator itr_end = mMembers.end(); + const MemberList::const_iterator itr_end = mMembers.end(); while (itr != itr_end) { if ((*itr) && (*itr)->mId == member->mId && @@ -238,10 +240,10 @@ bool Party::isMember(PartyMember *member) const return false; } -bool Party::isMember(int id) const +bool Party::isMember(const int id) const { MemberList::const_iterator itr = mMembers.begin(); - MemberList::const_iterator itr_end = mMembers.end(); + const MemberList::const_iterator itr_end = mMembers.end(); while (itr != itr_end) { if ((*itr) && (*itr)->mId == id) @@ -255,7 +257,7 @@ bool Party::isMember(int id) const bool Party::isMember(const std::string &name) const { MemberList::const_iterator itr = mMembers.begin(); - MemberList::const_iterator itr_end = mMembers.end(); + const MemberList::const_iterator itr_end = mMembers.end(); while (itr != itr_end) { if ((*itr) && (*itr)->getName() == name) @@ -270,7 +272,7 @@ void Party::getNames(StringVect &names) const { names.clear(); MemberList::const_iterator it = mMembers.begin(); - MemberList::const_iterator it_end = mMembers.end(); + const MemberList::const_iterator it_end = mMembers.end(); while (it != it_end) { if (*it) @@ -283,7 +285,7 @@ void Party::getNamesSet(std::set<std::string> &names) const { names.clear(); MemberList::const_iterator it = mMembers.begin(); - MemberList::const_iterator it_end = mMembers.end(); + const MemberList::const_iterator it_end = mMembers.end(); while (it != it_end) { if (*it) @@ -292,12 +294,12 @@ void Party::getNamesSet(std::set<std::string> &names) const } } -Party *Party::getParty(short id) +Party *Party::getParty(const short id) { - PartyMap::const_iterator it = parties.find(id); + const PartyMap::const_iterator it = parties.find(id); if (it != parties.end()) return it->second; - Party *party = new Party(id); + Party *const party = new Party(id); parties[id] = party; return party; } diff --git a/src/party.h b/src/party.h index 0f7c6eee4..870122383 100644 --- a/src/party.h +++ b/src/party.h @@ -41,13 +41,13 @@ public: bool getLeader() const { return mLeader; } - void setLeader(bool leader) + void setLeader(const bool leader) { mLeader = leader; setDisplayBold(leader); } protected: friend class Party; - PartyMember(Party *party, int id, const std::string &name); + PartyMember(Party *const party, const int id, const std::string &name); Party *mParty; bool mLeader; @@ -66,14 +66,14 @@ public: /** * Adds member to the list. */ - PartyMember *addMember(int id, const std::string &name); + PartyMember *addMember(const int id, const std::string &name); /** * Find a member by ID. * * @return the member with the given ID, or NULL if they don't exist. */ - PartyMember *getMember(int id) const; + PartyMember *getMember(const int id) const; /** * Find a member by name. @@ -99,12 +99,12 @@ public: /** * Removes a member from the party. */ - void removeMember(PartyMember *member); + void removeMember(const PartyMember *const member); /** * Removes a member from the party. */ - void removeMember(int id); + void removeMember(const int id); /** * Removes a member from the party. @@ -123,7 +123,7 @@ public: int getNumberOfElements() { return static_cast<int>(mMembers.size()); } - Avatar *getAvatarAt(int i); + Avatar *getAvatarAt(const int i); /** * Get whether user can invite users to this party. @@ -132,11 +132,11 @@ public: bool getInviteRights() const { return mCanInviteUsers; } - void setRights(short rights); + void setRights(const short rights); - bool isMember(PartyMember *member) const; + bool isMember(const PartyMember *const member) const; - bool isMember(int id) const; + bool isMember(const int id) const; bool isMember(const std::string &name) const; @@ -151,7 +151,7 @@ public: MemberList *getMembers() { return &mMembers; } - static Party *getParty(short id); + static Party *getParty(const short id); static void clearParties(); @@ -162,7 +162,7 @@ private: /** * Constructor with party id passed to it. */ - Party(short id); + Party(const short id); virtual ~Party(); diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp index d49609d73..29c538bfc 100644 --- a/src/playerinfo.cpp +++ b/src/playerinfo.cpp @@ -58,7 +58,7 @@ int mLevelProgress = 0; // --- Triggers --------------------------------------------------------------- -void triggerAttr(int id, int old) +void triggerAttr(const int id, const int old) { DepricatedEvent event(EVENT_UPDATEATTRIBUTE); event.setInt("id", id); @@ -67,9 +67,10 @@ void triggerAttr(int id, int old) DepricatedEvent::trigger(CHANNEL_ATTRIBUTES, event); } -void triggerStat(int id, const std::string &changed, int old1, int old2) +void triggerStat(const int id, const std::string &changed, + const int old1, const int old2) { - StatMap::const_iterator it = mData.mStats.find(id); + const StatMap::const_iterator it = mData.mStats.find(id); if (it == mData.mStats.end()) return; @@ -88,18 +89,18 @@ void triggerStat(int id, const std::string &changed, int old1, int old2) // --- Attributes ------------------------------------------------------------- -int getAttribute(Attribute id) +int getAttribute(const Attribute id) { - IntMap::const_iterator it = mData.mAttributes.find(id); + const IntMap::const_iterator it = mData.mAttributes.find(id); if (it != mData.mAttributes.end()) return it->second; else return 0; } -void setAttribute(Attribute id, int value, bool notify) +void setAttribute(const Attribute id, const int value, const bool notify) { - int old = mData.mAttributes[id]; + const int old = mData.mAttributes[id]; mData.mAttributes[id] = value; if (notify) triggerAttr(id, old); @@ -107,52 +108,52 @@ void setAttribute(Attribute id, int value, bool notify) // --- Stats ------------------------------------------------------------------ -int getStatBase(Attribute id) +int getStatBase(const Attribute id) { - StatMap::const_iterator it = mData.mStats.find(id); + const StatMap::const_iterator it = mData.mStats.find(id); if (it != mData.mStats.end()) return it->second.base; else return 0; } -void setStatBase(Attribute id, int value, bool notify) +void setStatBase(const Attribute id, const int value, const bool notify) { - int old = mData.mStats[id].base; + const int old = mData.mStats[id].base; mData.mStats[id].base = value; if (notify) triggerStat(id, "base", old); } -int getStatMod(Attribute id) +int getStatMod(const Attribute id) { - StatMap::const_iterator it = mData.mStats.find(id); + const StatMap::const_iterator it = mData.mStats.find(id); if (it != mData.mStats.end()) return it->second.mod; else return 0; } -void setStatMod(Attribute id, int value, bool notify) +void setStatMod(const Attribute id, const int value, const bool notify) { - int old = mData.mStats[id].mod; + const int old = mData.mStats[id].mod; mData.mStats[id].mod = value; if (notify) triggerStat(id, "mod", old); } -int getStatEffective(Attribute id) +int getStatEffective(const Attribute id) { - StatMap::const_iterator it = mData.mStats.find(id); + const StatMap::const_iterator it = mData.mStats.find(id); if (it != mData.mStats.end()) return it->second.base + it->second.mod; else return 0; } -std::pair<int, int> getStatExperience(Attribute id) +std::pair<int, int> getStatExperience(const Attribute id) { - StatMap::const_iterator it = mData.mStats.find(id); + const StatMap::const_iterator it = mData.mStats.find(id); int a, b; if (it != mData.mStats.end()) { @@ -167,12 +168,13 @@ std::pair<int, int> getStatExperience(Attribute id) return std::pair<int, int>(a, b); } -void setStatExperience(Attribute id, int have, int need, bool notify) +void setStatExperience(const Attribute id, const int have, + const int need, const bool notify) { Stat &stat = mData.mStats[id]; - int oldExp = stat.exp; - int oldExpNeed = stat.expNeed; + const int oldExp = stat.exp; + const int oldExpNeed = stat.expNeed; stat.exp = have; stat.expNeed = need; if (notify) @@ -194,10 +196,11 @@ void clearInventory() mInventory->clear(); } -void setInventoryItem(int index, int id, int amount, int refine) +void setInventoryItem(const int index, const int id, + const int amount, const int refine) { bool equipment = false; - int itemType = ItemDB::get(id).getType(); + const int itemType = ItemDB::get(id).getType(); if (itemType != ITEM_UNUSABLE && itemType != ITEM_USABLE) equipment = true; if (mInventory) @@ -209,7 +212,7 @@ Equipment *getEquipment() return mEquipment; } -Item *getEquipment(unsigned int slot) +Item *getEquipment(const unsigned int slot) { if (mEquipment) return mEquipment->getEquipment(slot); @@ -217,7 +220,7 @@ Item *getEquipment(unsigned int slot) return nullptr; } -void setEquipmentBackend(Equipment::Backend *backend) +void setEquipmentBackend(Equipment::Backend *const backend) { if (mEquipment) mEquipment->setBackend(backend); @@ -225,7 +228,8 @@ void setEquipmentBackend(Equipment::Backend *backend) // --- Specials --------------------------------------------------------------- -void setSpecialStatus(int id, int current, int max, int recharge) +void setSpecialStatus(const int id, const int current, + const int max, const int recharge) { logger->log("SpecialUpdate Skill #%d -- (%d/%d) -> %d", id, current, max, recharge); @@ -246,7 +250,7 @@ void setBackend(const PlayerInfoBackend &backend) mData = backend; } -void setCharId(int charId) +void setCharId(const int charId) { mCharId = charId; } @@ -278,9 +282,9 @@ bool isTrading() return mTrading; } -void setTrading(bool trading) +void setTrading(const bool trading) { - bool notify = mTrading != trading; + const bool notify = mTrading != trading; mTrading = trading; if (notify) @@ -293,7 +297,7 @@ void setTrading(bool trading) void updateAttrs() { - int attr = Net::getPlayerHandler()->getAttackLocation(); + const int attr = Net::getPlayerHandler()->getAttackLocation(); if (attr != -1 && getStatBase(ATTACK_DELAY)) { setStatBase(static_cast<PlayerInfo::Attribute>(ATTACK_SPEED), @@ -329,7 +333,7 @@ public: { if (event.getName() == EVENT_STATECHANGE) { - int newState = event.getInt("newState"); + const int newState = event.getInt("newState"); if (newState == STATE_GAME) { diff --git a/src/playerinfo.h b/src/playerinfo.h index 46204638f..63612166a 100644 --- a/src/playerinfo.h +++ b/src/playerinfo.h @@ -103,40 +103,43 @@ namespace PlayerInfo /** * Returns the value of the given attribute. */ - int getAttribute(Attribute id); + int getAttribute(const Attribute id); /** * Changes the value of the given attribute. */ - void setAttribute(Attribute id, int value, bool notify = true); + void setAttribute(const Attribute id, const int value, + const bool notify = true); // --- Stats ------------------------------------------------------------------ /** * Returns the base value of the given stat. */ - int getStatBase(Attribute id); + int getStatBase(const Attribute id); /** * Changes the base value of the given stat. */ - void setStatBase(Attribute id, int value, bool notify = true); + void setStatBase(const Attribute id, const int value, + const bool notify = true); /** * Returns the modifier for the given stat. */ - int getStatMod(Attribute id); + int getStatMod(const Attribute id); /** * Changes the modifier for the given stat. */ - void setStatMod(Attribute id, int value, bool notify = true); + void setStatMod(const Attribute id, const int value, + const bool notify = true); /** * Returns the current effective value of the given stat. Effective is base * + mod */ - int getStatEffective(Attribute id); + int getStatEffective(const Attribute id); /** * Changes the level of the given stat. @@ -146,13 +149,13 @@ namespace PlayerInfo /** * Returns the experience of the given stat. */ - std::pair<int, int> getStatExperience(Attribute id); + std::pair<int, int> getStatExperience(const Attribute id); /** * Changes the experience of the given stat. */ - void setStatExperience(Attribute id, int have, - int need, bool notify = true); + void setStatExperience(const Attribute id, const int have, + const int need, const bool notify = true); // --- Inventory / Equipment -------------------------------------------------- @@ -169,7 +172,8 @@ namespace PlayerInfo /** * Changes the inventory item at the given slot. */ - void setInventoryItem(int index, int id, int amount, int refine); + void setInventoryItem(const int index, const int id, + const int amount, const int refine); /** * Returns the player's equipment. @@ -179,14 +183,15 @@ namespace PlayerInfo /** * Returns the player's equipment at the given slot. */ - Item *getEquipment(unsigned int slot); + Item *getEquipment(const unsigned int slot); // --- Specials --------------------------------------------------------------- /** * Changes the status of the given special. */ - void setSpecialStatus(int id, int current, int max, int recharge); + void setSpecialStatus(const int id, const int current, + const int max, const int recharge); /** * Returns the status of the given special. @@ -200,7 +205,7 @@ namespace PlayerInfo */ void setBackend(const PlayerInfoBackend &backend); - void setCharId(int charId); + void setCharId(const int charId); int getCharId(); @@ -218,7 +223,7 @@ namespace PlayerInfo /** * Sets whether the player is currently involved in trade or not. */ - void setTrading(bool trading); + void setTrading(const bool trading); void updateAttrs(); @@ -233,14 +238,14 @@ namespace PlayerInfo void triggerAttr(int id); - void triggerAttr(int id, int old); + void triggerAttr(const int id, const int old); void triggerStat(int id); - void triggerStat(int id, const std::string &changed, - int old1, int old2 = 0); + void triggerStat(const int id, const std::string &changed, + const int old1, const int old2 = 0); - void setEquipmentBackend(Equipment::Backend *backend); + void setEquipmentBackend(Equipment::Backend *const backend); } // namespace PlayerInfo diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp index e7f4aeb2f..e85fd21b6 100644 --- a/src/playerrelations.cpp +++ b/src/playerrelations.cpp @@ -51,7 +51,8 @@ typedef PlayerRelationListeners::const_iterator PlayerRelationListenersCIter; class SortPlayersFunctor { public: - bool operator() (const std::string &str1, const std::string &str2) + bool operator() (const std::string &str1, + const std::string &str2) const { std::string s1 = str1; std::string s2 = str2; @@ -94,7 +95,7 @@ public: if (!(*container)[name]) { - int v = cobj->getValueInt(RELATION, + const int v = cobj->getValueInt(RELATION, static_cast<int>(PlayerRelation::NEUTRAL)); (*container)[name] = new PlayerRelation( @@ -119,7 +120,7 @@ const unsigned int PlayerRelation::RELATION_PERMISSIONS[RELATIONS_NR] = /* ENEMY2 */ EMOTE | SPEECH_FLOAT | SPEECH_LOG | WHISPER | TRADE }; -PlayerRelation::PlayerRelation(Relation relation) : +PlayerRelation::PlayerRelation(const Relation relation) : mRelation(relation) { } @@ -154,14 +155,14 @@ void PlayerRelationsManager::clear() names = nullptr; } -#define PERSIST_IGNORE_LIST "persistent-player-list" -#define PLAYER_IGNORE_STRATEGY "player-ignore-strategy" -#define DEFAULT_PERMISSIONS "default-player-permissions" +static const char *const PERSIST_IGNORE_LIST = "persistent-player-list"; +static const char *const PLAYER_IGNORE_STRATEGY = "player-ignore-strategy"; +static const char *const DEFAULT_PERMISSIONS = "default-player-permissions"; int PlayerRelationsManager::getPlayerIgnoreStrategyIndex( const std::string &name) { - std::vector<PlayerIgnoreStrategy *> *strategies + std::vector<PlayerIgnoreStrategy *> *const strategies = getPlayerIgnoreStrategies(); if (!strategies) @@ -176,7 +177,7 @@ int PlayerRelationsManager::getPlayerIgnoreStrategyIndex( return -1; } -void PlayerRelationsManager::load(bool oldConfig) +void PlayerRelationsManager::load(const bool oldConfig) { Configuration *cfg; if (oldConfig) @@ -191,7 +192,7 @@ void PlayerRelationsManager::load(bool oldConfig) std::string ignore_strategy_name = cfg->getValue(PLAYER_IGNORE_STRATEGY, DEFAULT_IGNORE_STRATEGY); - int ignore_strategy_index = getPlayerIgnoreStrategyIndex( + const int ignore_strategy_index = getPlayerIgnoreStrategyIndex( ignore_strategy_name); if (ignore_strategy_index >= 0) @@ -252,7 +253,7 @@ void PlayerRelationsManager::signalUpdate(const std::string &name) if (actorSpriteManager) { - Being* being = actorSpriteManager->findBeingByName( + Being *const being = actorSpriteManager->findBeingByName( name, Being::PLAYER); if (being && being->getType() == Being::PLAYER) @@ -261,9 +262,9 @@ void PlayerRelationsManager::signalUpdate(const std::string &name) } unsigned int PlayerRelationsManager::checkPermissionSilently( - const std::string &player_name, unsigned int flags) + const std::string &player_name, const unsigned int flags) { - PlayerRelation *r = mRelations[player_name]; + const PlayerRelation *const r = mRelations[player_name]; if (!r) { return mDefaultPermissions & flags; @@ -296,7 +297,8 @@ unsigned int PlayerRelationsManager::checkPermissionSilently( } } -bool PlayerRelationsManager::hasPermission(Being *being, unsigned int flags) +bool PlayerRelationsManager::hasPermission(const Being *const being, + unsigned int flags) { if (!being) return false; @@ -307,20 +309,21 @@ bool PlayerRelationsManager::hasPermission(Being *being, unsigned int flags) } bool PlayerRelationsManager::hasPermission(const std::string &name, - unsigned int flags) + const unsigned int flags) { if (!actorSpriteManager) return false; - unsigned int rejections = flags & ~checkPermissionSilently(name, flags); - bool permitted = (rejections == 0); + const unsigned int rejections = flags + & ~checkPermissionSilently(name, flags); + const bool permitted = (rejections == 0); if (!permitted) { // execute `ignore' strategy, if possible if (mIgnoreStrategy) { - Being *b = actorSpriteManager->findBeingByName( + Being *const b = actorSpriteManager->findBeingByName( name, ActorSprite::PLAYER); if (b && b->getType() == ActorSprite::PLAYER) @@ -332,7 +335,8 @@ bool PlayerRelationsManager::hasPermission(const std::string &name, } void PlayerRelationsManager::setRelation(const std::string &player_name, - PlayerRelation::Relation relation) + const PlayerRelation::Relation + relation) { if (!player_node || (relation != PlayerRelation::NEUTRAL && player_node->getName() == player_name)) @@ -340,7 +344,7 @@ void PlayerRelationsManager::setRelation(const std::string &player_name, return; } - PlayerRelation *r = mRelations[player_name]; + PlayerRelation *const r = mRelations[player_name]; if (!r) mRelations[player_name] = new PlayerRelation(relation); else @@ -351,7 +355,7 @@ void PlayerRelationsManager::setRelation(const std::string &player_name, StringVect * PlayerRelationsManager::getPlayers() { - StringVect *retval = new StringVect(); + StringVect *const retval = new StringVect(); for (PlayerRelationsCIter it = mRelations.begin(), it_end = mRelations.end(); it != it_end; ++ it) @@ -366,9 +370,9 @@ StringVect * PlayerRelationsManager::getPlayers() } StringVect *PlayerRelationsManager::getPlayersByRelation( - PlayerRelation::Relation rel) + const PlayerRelation::Relation rel) { - StringVect *retval = new StringVect(); + StringVect *const retval = new StringVect(); for (PlayerRelationsCIter it = mRelations.begin(), it_end = mRelations.end(); it != it_end; ++ it) @@ -410,7 +414,7 @@ unsigned int PlayerRelationsManager::getDefault() const return mDefaultPermissions; } -void PlayerRelationsManager::setDefault(unsigned int permissions) +void PlayerRelationsManager::setDefault(const unsigned int permissions) { mDefaultPermissions = permissions; @@ -423,7 +427,7 @@ void PlayerRelationsManager::ignoreTrade(std::string name) if (name.empty()) return; - PlayerRelation::Relation relation = getRelation(name); + const PlayerRelation::Relation relation = getRelation(name); if (relation == PlayerRelation::IGNORED || relation == PlayerRelation::DISREGARDED @@ -443,7 +447,7 @@ bool PlayerRelationsManager::checkBadRelation(std::string name) if (name.empty()) return true; - PlayerRelation::Relation relation = getRelation(name); + const PlayerRelation::Relation relation = getRelation(name); if (relation == PlayerRelation::IGNORED || relation == PlayerRelation::DISREGARDED @@ -469,7 +473,8 @@ public: mShortName = PLAYER_IGNORE_STRATEGY_NOP; } - virtual void ignore(Being *being A_UNUSED, unsigned int flags A_UNUSED) + virtual void ignore(Being *const being A_UNUSED, + const unsigned int flags A_UNUSED) { } }; @@ -483,7 +488,7 @@ public: mShortName = "dotdotdot"; } - virtual void ignore(Being *being, unsigned int flags A_UNUSED) + virtual void ignore(Being *const being, const unsigned int flags A_UNUSED) { if (!being) return; @@ -503,7 +508,7 @@ public: mShortName = "blinkname"; } - virtual void ignore(Being *being, unsigned int flags A_UNUSED) + virtual void ignore(Being *const being, const unsigned int flags A_UNUSED) { if (!being) return; @@ -516,7 +521,7 @@ public: class PIS_emote : public PlayerIgnoreStrategy { public: - PIS_emote(uint8_t emote_nr, const std::string &description, + PIS_emote(const uint8_t emote_nr, const std::string &description, const std::string &shortname) : mEmotion(emote_nr) { @@ -524,7 +529,7 @@ public: mShortName = shortname; } - virtual void ignore(Being *being, unsigned int flags A_UNUSED) + virtual void ignore(Being *const being, const unsigned int flags A_UNUSED) { if (!being) return; @@ -567,7 +572,7 @@ bool PlayerRelationsManager::isGoodName(std::string name) return status; } -bool PlayerRelationsManager::isGoodName(Being *being) +bool PlayerRelationsManager::isGoodName(Being *const being) { bool status(false); diff --git a/src/playerrelations.h b/src/playerrelations.h index 91f5c2e9e..e4a5a9e98 100644 --- a/src/playerrelations.h +++ b/src/playerrelations.h @@ -60,7 +60,7 @@ struct PlayerRelation ENEMY2 = 6 }; - PlayerRelation(Relation relation); + PlayerRelation(const Relation relation); Relation mRelation; // bitmask for all of the above }; @@ -81,7 +81,7 @@ class PlayerIgnoreStrategy /** * Handle the ignoring of the indicated action by the indicated player. */ - virtual void ignore(Being *being, unsigned int flags) = 0; + virtual void ignore(Being *const being, const unsigned int flags) = 0; }; class PlayerRelationsListener @@ -116,7 +116,7 @@ class PlayerRelationsManager /** * Load configuration from our config file, or substitute defaults. */ - void load(bool oldConfig = false); + void load(const bool oldConfig = false); /** * Save configuration to our config file. @@ -128,22 +128,22 @@ class PlayerRelationsManager * the specified flags. */ unsigned int checkPermissionSilently(const std::string &player_name, - unsigned int flags); + const unsigned int flags); /** * Tests whether the player in question is being ignored for any of the * actions in the specified flags. If so, trigger appropriate side effects * if requested by the player. */ - bool hasPermission(Being *being, unsigned int flags); + bool hasPermission(const Being *const being, const unsigned int flags); - bool hasPermission(const std::string &being, unsigned int flags); + bool hasPermission(const std::string &being, const unsigned int flags); /** * Updates the relationship with this player. */ void setRelation(const std::string &name, - PlayerRelation::Relation relation); + const PlayerRelation::Relation relation); /** * Updates the relationship with this player. @@ -163,7 +163,7 @@ class PlayerRelationsManager /** * Sets the default permissions. */ - void setDefault(unsigned int permissions); + void setDefault(const unsigned int permissions); /** * Retrieves all known player ignore strategies. @@ -184,7 +184,7 @@ class PlayerRelationsManager /** * Sets the strategy to call when ignoring players. */ - void setPlayerIgnoreStrategy(PlayerIgnoreStrategy *strategy) + void setPlayerIgnoreStrategy(PlayerIgnoreStrategy *const strategy) { mIgnoreStrategy = strategy; } /** @@ -202,7 +202,7 @@ class PlayerRelationsManager */ StringVect *getPlayers(); - StringVect *getPlayersByRelation(PlayerRelation::Relation rel); + StringVect *getPlayersByRelation(const PlayerRelation::Relation rel); /** * Removes all recorded player info. @@ -217,7 +217,7 @@ class PlayerRelationsManager void ignoreTrade(std::string name); - bool isGoodName(Being *being); + bool isGoodName(Being *const being); bool isGoodName(std::string name); @@ -226,13 +226,13 @@ class PlayerRelationsManager * * @param value Whether to persist ignores */ - void setPersistIgnores(bool value) + void setPersistIgnores(const bool value) { mPersistIgnores = value; } - void addListener(PlayerRelationsListener *listener) + void addListener(PlayerRelationsListener *const listener) { mListeners.push_back(listener); } - void removeListener(PlayerRelationsListener *listener) + void removeListener(PlayerRelationsListener *const listener) { mListeners.remove(listener); } bool checkBadRelation(std::string name); diff --git a/src/position.h b/src/position.h index 2e10aebe2..60c762310 100644 --- a/src/position.h +++ b/src/position.h @@ -31,7 +31,7 @@ */ struct Position { - Position(int x0, int y0): + Position(const int x0, const int y0) : x(x0), y(y0) { } diff --git a/src/properties.h b/src/properties.h index 501a20a57..63dcd9afc 100644 --- a/src/properties.h +++ b/src/properties.h @@ -50,7 +50,7 @@ class Properties const std::string getProperty(const std::string &name, const std::string &def = "") const { - PropertyMap::const_iterator i = mProperties.find(name); + const PropertyMap::const_iterator i = mProperties.find(name); return (i != mProperties.end()) ? i->second : def; } @@ -62,9 +62,10 @@ class Properties * @return the value of the given property or the given default when it * doesn't exist. */ - float getFloatProperty(const std::string &name, float def = 0.0f) const + float getFloatProperty(const std::string &name, + const float def = 0.0f) const { - PropertyMap::const_iterator i = mProperties.find(name); + const PropertyMap::const_iterator i = mProperties.find(name); float ret = def; if (i != mProperties.end()) { @@ -83,9 +84,10 @@ class Properties * @return the value of the given property or the given default when it * doesn't exist. */ - bool getBoolProperty(const std::string &name, bool def = false) const + bool getBoolProperty(const std::string &name, + const bool def = false) const { - PropertyMap::const_iterator i = mProperties.find(name); + const PropertyMap::const_iterator i = mProperties.find(name); bool ret = def; if (i != mProperties.end()) { |