summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-02-05 23:41:50 +0300
committerAndrei Karas <akaras@inbox.ru>2013-02-05 23:41:50 +0300
commit98fff0b1a6fc9103759855e888b6be241fcb8510 (patch)
tree168edf43c65ba2fdaa2667424854009c2fc0b7dc
parent126b1470842302537b0bc5e4527cf7fd540a9125 (diff)
downloadmanaverse-98fff0b1a6fc9103759855e888b6be241fcb8510.tar.gz
manaverse-98fff0b1a6fc9103759855e888b6be241fcb8510.tar.bz2
manaverse-98fff0b1a6fc9103759855e888b6be241fcb8510.tar.xz
manaverse-98fff0b1a6fc9103759855e888b6be241fcb8510.zip
Add missing checks to being class.
-rw-r--r--src/being.cpp186
-rw-r--r--src/being.h12
-rw-r--r--src/compoundsprite.cpp7
-rw-r--r--src/compoundsprite.h4
4 files changed, 94 insertions, 115 deletions
diff --git a/src/being.cpp b/src/being.cpp
index e2452f997..29ffefcfd 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -338,7 +338,8 @@ void Being::setSubtype(const uint16_t subtype)
setRaceName(info.getName());
}
- setSprite(Net::getCharHandler()->baseSprite(), id);
+ if (Net::getCharHandler())
+ setSprite(Net::getCharHandler()->baseSprite(), id);
}
}
@@ -457,8 +458,9 @@ void Being::setSpeech(const std::string &text, int time)
if (mSpeech.empty())
return;
- if (!time && mSpeech.size() < 200)
- time = static_cast<int>(SPEECH_TIME - 300 + (3 * mSpeech.size()));
+ const int sz = mSpeech.size();
+ if (!time && sz < 200)
+ time = static_cast<int>(SPEECH_TIME - 300 + (3 * sz));
if (time < static_cast<int>(SPEECH_MIN_TIME))
time = static_cast<int>(SPEECH_MIN_TIME);
@@ -520,7 +522,7 @@ void Being::takeDamage(Being *const attacker, const int amount,
return;
gcn::Font *font = nullptr;
- std::string damage = amount ? toString(amount) : type == FLEE ?
+ const std::string damage = amount ? toString(amount) : type == FLEE ?
_("dodge") : _("miss");
const gcn::Color *color;
@@ -645,7 +647,7 @@ void Being::takeDamage(Being *const attacker, const int amount,
if (effectManager)
{
- int hitEffectId = getHitEffect(attacker, type, attackId);
+ const int hitEffectId = getHitEffect(attacker, type, attackId);
if (hitEffectId >= 0)
effectManager->trigger(hitEffectId, this);
}
@@ -654,7 +656,7 @@ void Being::takeDamage(Being *const attacker, const int amount,
{
if (effectManager)
{
- int hitEffectId = getHitEffect(attacker,
+ const int hitEffectId = getHitEffect(attacker,
MISS, attackId);
if (hitEffectId >= 0)
effectManager->trigger(hitEffectId, this);
@@ -673,50 +675,47 @@ int Being::getHitEffect(const Being *const attacker,
int hitEffectId = 0;
if (type != SKILL)
{
- const ItemInfo *attackerWeapon = attacker->getEquippedWeapon();
- if (attackerWeapon && attacker->getType() == PLAYER)
+ if (attacker)
{
- if (type == MISS)
- hitEffectId = attackerWeapon->getMissEffectId();
- else if (type != CRITICAL)
- hitEffectId = attackerWeapon->getHitEffectId();
- else
- hitEffectId = attackerWeapon->getCriticalHitEffectId();
- }
- else if (attacker && attacker->getType() == MONSTER)
- {
- const BeingInfo *const info = attacker->getInfo();
- if (info)
+ const ItemInfo *attackerWeapon = attacker->getEquippedWeapon();
+ if (attackerWeapon && attacker->getType() == PLAYER)
{
- const Attack *atk = info->getAttack(attackId);
- if (atk)
- {
- if (type == MISS)
- hitEffectId = atk->mMissEffectId;
- else if (type != CRITICAL)
- hitEffectId = atk->mHitEffectId;
- else
- hitEffectId = atk->mCriticalHitEffectId;
- }
+ if (type == MISS)
+ hitEffectId = attackerWeapon->getMissEffectId();
+ else if (type != CRITICAL)
+ hitEffectId = attackerWeapon->getHitEffectId();
else
+ hitEffectId = attackerWeapon->getCriticalHitEffectId();
+ }
+ else if (attacker->getType() == MONSTER)
+ {
+ const BeingInfo *const info = attacker->getInfo();
+ if (info)
{
- if (type == MISS)
- hitEffectId = paths.getIntValue("missEffectId");
- else if (type != CRITICAL)
- hitEffectId = paths.getIntValue("hitEffectId");
+ const Attack *atk = info->getAttack(attackId);
+ if (atk)
+ {
+ if (type == MISS)
+ hitEffectId = atk->mMissEffectId;
+ else if (type != CRITICAL)
+ hitEffectId = atk->mHitEffectId;
+ else
+ hitEffectId = atk->mCriticalHitEffectId;
+ }
else
- hitEffectId = paths.getIntValue("criticalHitEffectId");
+ {
+ hitEffectId = getDefaultEffectId(type);
+ }
}
}
+ else
+ {
+ hitEffectId = getDefaultEffectId(type);
+ }
}
else
{
- if (type == MISS)
- hitEffectId = paths.getIntValue("missEffectId");
- else if (type != CRITICAL)
- hitEffectId = paths.getIntValue("hitEffectId");
- else
- hitEffectId = paths.getIntValue("criticalHitEffectId");
+ hitEffectId = getDefaultEffectId(type);
}
}
else
@@ -727,6 +726,16 @@ int Being::getHitEffect(const Being *const attacker,
return hitEffectId;
}
+int Being::getDefaultEffectId(const int type)
+{
+ if (type == MISS)
+ return paths.getIntValue("missEffectId");
+ else if (type != CRITICAL)
+ return paths.getIntValue("hitEffectId");
+ else
+ return paths.getIntValue("criticalHitEffectId");
+}
+
void Being::handleAttack(Being *const victim, const int damage,
const int attackId)
{
@@ -1110,12 +1119,13 @@ void Being::setAction(const Action &action, const int attackId)
//attack particle effect
if (Particle::enabled)
{
- int effectId = mInfo->getAttack(attackId)->mEffectId;
+ const int effectId = mInfo->getAttack(attackId)->mEffectId;
- int rotation = 0;
+ int rotation;
switch (mSpriteDirection)
{
case DIRECTION_DOWN:
+ default:
rotation = 0;
break;
case DIRECTION_LEFT:
@@ -1127,8 +1137,6 @@ void Being::setAction(const Action &action, const int attackId)
case DIRECTION_RIGHT:
rotation = 270;
break;
- default:
- break;
}
if (effectManager && effectId >= 0)
effectManager->trigger(effectId, this, rotation);
@@ -1416,45 +1424,6 @@ void Being::logic()
/ mAttackSpeed;
}
-/*
- //attack particle effect
- if (mEquippedWeapon)
- {
- particleEffect = mEquippedWeapon->getParticleEffect();
-
- if (!particleEffect.empty() &&
- findSameSubstring(particleEffect,
- paths.getStringValue("particles")).empty())
- {
- particleEffect = paths.getStringValue("particles")
- + particleEffect;
- }
- }
- else if (mInfo && mInfo->getAttack(mAttackType))
- {
- particleEffect = mInfo->getAttack(mAttackType)
- ->particleEffect;
- }
-
- if (particleEngine && !particleEffect.empty()
- && Particle::enabled && curFrame == 1)
- {
- int rotation = 0;
-
- switch (mDirection)
- {
- case DOWN: rotation = 0; break;
- case LEFT: rotation = 90; break;
- case UP: rotation = 180; break;
- case RIGHT: rotation = 270; break;
- default: break;
- }
- Particle *const p = particleEngine->addEffect(
- particleEffect, 0, 0, rotation);
- controlParticle(p);
- }
-*/
-
if (this == player_node && curFrame >= frameCount)
nextTile();
@@ -1476,7 +1445,6 @@ void Being::logic()
ActorSprite::logic();
-// int frameCount = static_cast<int>(getFrameCount());
if (frameCount < 10)
frameCount = 10;
@@ -1503,8 +1471,10 @@ void Being::drawEmotion(Graphics *const graphics, const int offsetX,
if (emotionIndex >= 0 && emotionIndex <= EmoteDB::getLast())
{
- if (EmoteDB::getAnimation2(emotionIndex, true))
- EmoteDB::getAnimation2(emotionIndex)->draw(graphics, px, py);
+ const AnimatedSprite *const sprite = EmoteDB::getAnimation2(
+ emotionIndex, true);
+ if (sprite)
+ sprite->draw(graphics, px, py);
else
mEmotion = 0;
}
@@ -1560,7 +1530,6 @@ void Being::drawSpeech(const int offsetX, const int offsetY)
}
}
-/** TODO: eAthena only */
int Being::getOffset(const signed char pos, const signed char neg) const
{
// Check whether we're walking in the requested direction
@@ -1571,11 +1540,12 @@ int Being::getOffset(const signed char pos, const signed char neg) const
if (mMap)
{
+ const int time = get_elapsed_time(mActionTime);
offset = (pos == LEFT && neg == RIGHT) ?
- static_cast<int>((static_cast<float>(get_elapsed_time(mActionTime))
+ static_cast<int>((static_cast<float>(time)
* static_cast<float>(mMap->getTileWidth()))
/ static_cast<float>(mWalkSpeed.x)) :
- static_cast<int>((static_cast<float>(get_elapsed_time(mActionTime))
+ static_cast<int>((static_cast<float>(time)
* static_cast<float>(mMap->getTileHeight()))
/ static_cast<float>(mWalkSpeed.y));
}
@@ -1677,21 +1647,21 @@ void Being::showName()
return;
}
- std::string mDisplayName(mName);
+ std::string displayName(mName);
if (mType != MONSTER && (mShowGender || mShowLevel))
{
- mDisplayName += " ";
+ displayName += " ";
if (mShowLevel && getLevel() != 0)
- mDisplayName += toString(getLevel());
+ displayName += toString(getLevel());
- mDisplayName += getGenderSign();
+ displayName += getGenderSign();
}
if (mType == MONSTER)
{
if (config.getBoolValue("showMonstersTakedDamage"))
- mDisplayName += ", " + toString(getDamageTaken());
+ displayName += ", " + toString(getDamageTaken());
}
gcn::Font *font = nullptr;
@@ -1705,7 +1675,7 @@ void Being::showName()
font = gui->getSecureFont();
}
- mDispName = new FlashText(mDisplayName, getPixelX(), getPixelY(),
+ mDispName = new FlashText(displayName, getPixelX(), getPixelY(),
gcn::Graphics::CENTER, mNameColor, font);
updateCoords();
@@ -1752,7 +1722,8 @@ void Being::updateColors()
{
mNameColor = &userPalette->getColor(UserPalette::PARTY);
}
- else if (getGuild() && getGuild() == player_node->getGuild())
+ else if (player_node && getGuild()
+ && getGuild() == player_node->getGuild())
{
mNameColor = &userPalette->getColor(UserPalette::GUILD);
}
@@ -1821,17 +1792,16 @@ void Being::setSprite(const unsigned int slot, const int id,
else
{
const ItemInfo &info = ItemDB::get(id);
- std::string filename = info.getSprite(mGender, mSubType);
+ const std::string filename = info.getSprite(mGender, mSubType);
AnimatedSprite *equipmentSprite = nullptr;
if (!filename.empty())
{
if (color.empty())
color = info.getDyeColorsString(colorId);
- filename = combineDye(filename, color);
equipmentSprite = AnimatedSprite::delayedLoad(
- paths.getStringValue("sprites") + filename);
+ paths.getStringValue("sprites") + combineDye(filename, color));
}
if (equipmentSprite)
@@ -1880,7 +1850,7 @@ void Being::setHairColor(const unsigned int slot, const unsigned char color)
getSpriteID(slot)).getDyeColorsString(color));
}
-void Being::dumpSprites()
+void Being::dumpSprites() const
{
std::vector<int>::const_iterator it1 = mSpriteIDs.begin();
const std::vector<int>::const_iterator it1_end = mSpriteIDs.end();
@@ -2079,7 +2049,7 @@ void Being::setGM(const bool gm)
updateColors();
}
-void Being::talkTo()
+void Being::talkTo() const
{
if (!Client::limitPackets(PACKET_NPC_TALK))
return;
@@ -2097,7 +2067,8 @@ bool Being::draw(Graphics *const graphics,
return res;
}
-void Being::drawSprites(Graphics* graphics, int posX, int posY) const
+void Being::drawSprites(Graphics *const graphics,
+ const int posX, const int posY) const
{
const int sz = getNumberOfLayers();
for (int f = 0; f < sz; f ++)
@@ -2115,7 +2086,8 @@ void Being::drawSprites(Graphics* graphics, int posX, int posY) const
}
}
-void Being::drawSpritesSDL(Graphics* graphics, int posX, int posY) const
+void Being::drawSpritesSDL(Graphics *const graphics,
+ const int posX, const int posY) const
{
const size_t sz = size();
for (unsigned f = 0; f < sz; f ++)
@@ -2138,6 +2110,9 @@ bool Being::drawSpriteAt(Graphics *const graphics,
if (!mErased)
res = ActorSprite::drawSpriteAt(graphics, x, y);
+ if (!userPalette)
+ return res;
+
if (mHighlightMapPortals && mMap && mSubType == 45 && !mMap->getHasWarps())
{
graphics->setColor(userPalette->
@@ -2200,7 +2175,7 @@ void Being::drawHpBar(Graphics *const graphics, const int maxHP, const int hp,
const int x, const int y, const int width,
const int height) const
{
- if (maxHP <= 0)
+ if (maxHP <= 0 || !userPalette)
return;
if (!hp && maxHP < hp)
@@ -2560,7 +2535,8 @@ void Being::recalcSpritesOrder()
}
}
-int Being::searchSlotValue(std::vector<int> &slotRemap, const int val) const
+int Being::searchSlotValue(const std::vector<int> &slotRemap,
+ const int val) const
{
for (unsigned slot = 0; slot < size(); slot ++)
{
diff --git a/src/being.h b/src/being.h
index 384741afe..32508670b 100644
--- a/src/being.h
+++ b/src/being.h
@@ -605,10 +605,10 @@ class Being : public ActorSprite, public ConfigListener
int getEmotion() const A_WARN_UNUSED
{ return mEmotion; }
- virtual void drawSprites(Graphics* graphics,
+ virtual void drawSprites(Graphics *const graphics,
int posX, int posY) const override;
- virtual void drawSpritesSDL(Graphics* graphics,
+ virtual void drawSpritesSDL(Graphics *const graphics,
int posX, int posY) const override;
void drawHpBar(Graphics *const graphics, const int x, const int y,
@@ -677,7 +677,7 @@ class Being : public ActorSprite, public ConfigListener
bool canTalk() const A_WARN_UNUSED
{ return mType == NPC; }
- void talkTo();
+ void talkTo() const;
bool draw(Graphics *const graphics,
const int offsetX, const int offsetY) const override;
@@ -873,6 +873,8 @@ class Being : public ActorSprite, public ConfigListener
void showName();
+ static int getDefaultEffectId(const int type);
+
BeingInfo *mInfo;
int mActionTime; /**< Time spent in current action */
@@ -939,14 +941,14 @@ class Being : public ActorSprite, public ConfigListener
int getOffset(const signed char pos,
const signed char neg) const A_WARN_UNUSED;
- int searchSlotValue(std::vector<int> &slotRemap,
+ int searchSlotValue(const std::vector<int> &slotRemap,
const int val) const A_WARN_UNUSED;
void searchSlotValueItr(std::vector<int>::iterator &it, int &idx,
std::vector<int> &slotRemap,
const int val) const;
- void dumpSprites();
+ void dumpSprites() const;
const Type mType;
diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp
index ef956d8f4..01e144bf4 100644
--- a/src/compoundsprite.cpp
+++ b/src/compoundsprite.cpp
@@ -143,7 +143,8 @@ bool CompoundSprite::draw(Graphics *const graphics,
return false;
}
-void CompoundSprite::drawSprites(Graphics* graphics, int posX, int posY) const
+void CompoundSprite::drawSprites(Graphics *const graphics,
+ const int posX, const int posY) const
{
FOR_EACH (SpriteConstIterator, it, mSprites)
{
@@ -155,8 +156,8 @@ void CompoundSprite::drawSprites(Graphics* graphics, int posX, int posY) const
}
}
-void CompoundSprite::drawSpritesSDL(Graphics* graphics,
- int posX, int posY) const
+void CompoundSprite::drawSpritesSDL(Graphics *const graphics,
+ const int posX, const int posY) const
{
FOR_EACH (SpriteConstIterator, it, mSprites)
{
diff --git a/src/compoundsprite.h b/src/compoundsprite.h
index aa9b2d7b6..928c6b06f 100644
--- a/src/compoundsprite.h
+++ b/src/compoundsprite.h
@@ -107,10 +107,10 @@ public:
void ensureSize(size_t layerCount);
- virtual void drawSprites(Graphics* graphics,
+ virtual void drawSprites(Graphics *const graphics,
int posX, int posY) const;
- virtual void drawSpritesSDL(Graphics* graphics,
+ virtual void drawSpritesSDL(Graphics *const graphics,
int posX, int posY) const;
/**