diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-01-11 01:34:11 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-01-11 01:34:11 +0200 |
commit | fcced13d9972ac70f0f01f19583b7868e255b6a7 (patch) | |
tree | 9b01df102c5f9ba032ea0f9bc413dd707e99d88b /src/being.cpp | |
parent | 311783bebbe2bed366dca5097697ce34c690292d (diff) | |
parent | ef1b9856c86512fe73154c17da3ea98a7cd5f896 (diff) | |
download | manaplus-fcced13d9972ac70f0f01f19583b7868e255b6a7.tar.gz manaplus-fcced13d9972ac70f0f01f19583b7868e255b6a7.tar.bz2 manaplus-fcced13d9972ac70f0f01f19583b7868e255b6a7.tar.xz manaplus-fcced13d9972ac70f0f01f19583b7868e255b6a7.zip |
Merge branch 'master' into invfiler
Diffstat (limited to 'src/being.cpp')
-rw-r--r-- | src/being.cpp | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/src/being.cpp b/src/being.cpp index 08893c2f4..4f31e402c 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -71,6 +71,7 @@ #include "gui/widgets/chattab.h" #include "utils/dtor.h" +#include "utils/gettext.h" #include "utils/stringutils.h" #include "utils/xml.h" @@ -168,6 +169,7 @@ bool Being::mLowTraffic = true; bool Being::mDrawHotKeys = true; bool Being::mShowBattleEvents = false; bool Being::mShowMobHP = false; +bool Being::mShowOwnHP = false; std::list<BeingCacheEntry*> beingInfoCache; @@ -476,7 +478,7 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) gcn::Font *font = 0; std::string damage = amount ? toString(amount) : type == FLEE ? - "dodge" : "miss"; + _("dodge") : _("miss"); const gcn::Color *color; if (gui) @@ -566,7 +568,15 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) mDamageTaken += amount; if (mInfo) { - sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT)); + if (attacker) + { + sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT), + attacker->getTileX(), attacker->getTileY()); + } + else + { + sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT)); + } if (!mInfo->isStaticMaxHP()) { if (!mHP && mInfo->getMaxHP() < mDamageTaken) @@ -616,7 +626,7 @@ void Being::handleAttack(Being *victim, int damage, } sound.playSfx(mInfo->getSound((damage > 0) ? - SOUND_EVENT_HIT : SOUND_EVENT_MISS)); + SOUND_EVENT_HIT : SOUND_EVENT_MISS), mX, mY); } void Being::setName(const std::string &name) @@ -902,7 +912,7 @@ void Being::setAction(Action action, int attackType _UNUSED_) case DEAD: currentAction = SpriteAction::DEAD; if (mInfo) - sound.playSfx(mInfo->getSound(SOUND_EVENT_DIE)); + sound.playSfx(mInfo->getSound(SOUND_EVENT_DIE), mX, mY); break; case STAND: currentAction = SpriteAction::STAND; @@ -1550,6 +1560,7 @@ void Being::reReadConfig() mDrawHotKeys = config.getBoolValue("drawHotKeys"); mShowBattleEvents = config.getBoolValue("showBattleEvents"); mShowMobHP = config.getBoolValue("showMobHP"); + mShowOwnHP = config.getBoolValue("showOwnHP"); mUpdateConfigTime = cur_time; } @@ -1744,42 +1755,48 @@ bool Being::drawSpriteAt(Graphics *graphics, int x, int y) const 2 * attackRange + 32, 2 * attackRange + 32)); } - if (mShowMobHP && player_node && player_node->getTarget() == this + if (mShowMobHP && mInfo && player_node && player_node->getTarget() == this && getType() == MONSTER) { // show hp bar here - drawHpBar(graphics, x - 50 + 16, y + 32 - 6, 2 * 50, 4); + int maxHP = mMaxHP; + if (!maxHP) + maxHP = mInfo->getMaxHP(); + + drawHpBar(graphics, maxHP, mHP, mDamageTaken, + UserPalette::MONSTER_HP, UserPalette::MONSTER_HP2, + x - 50 + 16, y + 32 - 6, 2 * 50, 4); + } + if (mShowOwnHP && player_node == this && mAction != DEAD) + { + drawHpBar(graphics, PlayerInfo::getAttribute(MAX_HP), + PlayerInfo::getAttribute(HP), 0, + UserPalette::PLAYER_HP, UserPalette::PLAYER_HP2, + x - 50 + 16, y + 32 - 6, 2 * 50, 4); } return res; } -void Being::drawHpBar(Graphics *graphics, int x, int y, +void Being::drawHpBar(Graphics *graphics, int maxHP, int hp, int damage, + int color1, int color2, int x, int y, int width, int height) const { - if (!mInfo) - return; - - int maxHP = mMaxHP; - - if (!maxHP) - maxHP = mInfo->getMaxHP(); - if (maxHP <= 0) return; - if (!mHP && maxHP < mHP) + if (!hp && maxHP < hp) return; float p; - if (mHP) + if (hp) { - p = static_cast<float>(maxHP) / static_cast<float>(mHP); + p = static_cast<float>(maxHP) / static_cast<float>(hp); } - else if (maxHP != mDamageTaken) + else if (maxHP != damage) { p = static_cast<float>(maxHP) - / static_cast<float>(maxHP - mDamageTaken); + / static_cast<float>(maxHP - damage); } else { @@ -1791,8 +1808,7 @@ void Being::drawHpBar(Graphics *graphics, int x, int y, int dx = width / p; - graphics->setColor(userPalette->getColorWithAlpha( - UserPalette::MONSTER_HP)); + graphics->setColor(userPalette->getColorWithAlpha(color1)); graphics->fillRectangle(gcn::Rectangle( x, y, dx, height)); @@ -1800,8 +1816,7 @@ void Being::drawHpBar(Graphics *graphics, int x, int y, if (width - dx <= 0) return; - graphics->setColor(userPalette->getColorWithAlpha( - UserPalette::MONSTER_HP2)); + graphics->setColor(userPalette->getColorWithAlpha(color2)); graphics->fillRectangle(gcn::Rectangle( x + dx, y, width - dx, height)); |