From bdb6db2ab7ae4f2822cb63aeb39aa387f31aee4f Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Thu, 20 Oct 2011 11:03:04 +0000 Subject: [PATCH] Support for Aura of Magic Resistance. --- client/CCreatureWindow.cpp | 24 +++++++++++++++++++++++- lib/BattleState.cpp | 16 ++++++++++++++++ lib/BattleState.h | 1 + lib/CCreatureHandler.cpp | 4 ++-- lib/CCreatureSet.cpp | 29 ++++++++++++++++------------- 5 files changed, 58 insertions(+), 16 deletions(-) diff --git a/client/CCreatureWindow.cpp b/client/CCreatureWindow.cpp index 47aecdc1c..ad3bd62b5 100644 --- a/client/CCreatureWindow.cpp +++ b/client/CCreatureWindow.cpp @@ -127,6 +127,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * stackNode = c; else stackNode = StackNode; + const CStack *battleStack = dynamic_cast(stackNode); //only during battle heroOwner = HeroOwner; if (Stack->count) @@ -157,6 +158,27 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * } } + int magicResistance = 0; //handle it separately :/ + if (battleStack) + { + magicResistance = battleStack->magicResistance(); //include Aura of Resistance + } + else + { + magicResistance = stack->magicResistance(); //include Resiatance hero skill + } + if (magicResistance) + { + std::map >::const_iterator it = CGI->creh->stackBonuses.find(Bonus::MAGIC_RESISTANCE); + std::string description; + text = it->second.first; + description = it->second.second; + boost::algorithm::replace_first(description, "%d", boost::lexical_cast(magicResistance)); + Bonus b; + b.type = Bonus::MAGIC_RESISTANCE; + bonusItems.push_back (new CBonusItem(genRect(0, 0, 251, 57), text, description, stack->bonusToGraphics(&b))); + } + bonusRows = std::min ((int)((bonusItems.size() + 1) / 2), (conf.cc.resy - 230) / 60); amin(bonusRows, 4); amax(bonusRows, 1); @@ -244,7 +266,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * creatureArtifact = NULL; } - if(const CStack *battleStack = dynamic_cast(stackNode)) //only during battle + if (battleStack) //only during battle { //spell effects int printed=0; //how many effect pics have been printed diff --git a/lib/BattleState.cpp b/lib/BattleState.cpp index 1a904f8a1..ff47ed73e 100644 --- a/lib/BattleState.cpp +++ b/lib/BattleState.cpp @@ -2349,6 +2349,22 @@ ui32 CStack::Speed( int turn /*= 0*/ , bool useBind /* = false*/) const return speed; } +si32 CStack::magicResistance() const +{ + si32 magicResistance = base->magicResistance(); + int auraBonus = 0; + BOOST_FOREACH (CStack * stack, base->armyObj->battle->getAdjacentCreatures(this)) + { + if (stack->owner == owner) + { + amax(auraBonus, stack->valOfBonuses(Bonus::SPELL_RESISTANCE_AURA)); //max value + } + } + magicResistance += auraBonus; + amin (magicResistance, 100); + return magicResistance; +} + const Bonus * CStack::getEffect( ui16 id, int turn /*= 0*/ ) const { BOOST_FOREACH(Bonus *it, getBonusList()) diff --git a/lib/BattleState.h b/lib/BattleState.h index 2a724673f..d5304a70d 100644 --- a/lib/BattleState.h +++ b/lib/BattleState.h @@ -182,6 +182,7 @@ public: bool moved(int turn = 0) const; //if stack was already moved this turn bool canMove(int turn = 0) const; //if stack can move ui32 Speed(int turn = 0, bool useBind = false) const; //get speed of creature with all modificators + si32 magicResistance() const; //include aura of resistance static void stackEffectToFeature(std::vector & sf, const Bonus & sse); std::vector activeSpells() const; //returns vector of active spell IDs sorted by time of cast const CGHeroInstance *getMyHero() const; //if stack belongs to hero (directly or was by him summoned) returns hero, NULL otherwise diff --git a/lib/CCreatureHandler.cpp b/lib/CCreatureHandler.cpp index bce0714d9..baf347167 100644 --- a/lib/CCreatureHandler.cpp +++ b/lib/CCreatureHandler.cpp @@ -495,8 +495,8 @@ void CCreatureHandler::loadCreatures() } //handle magic resistance secondary skill premy, potentialy may be buggy - std::map >::iterator it = stackBonuses.find(Bonus::MAGIC_RESISTANCE); - stackBonuses[Bonus::SECONDARY_SKILL_PREMY] = std::pair(it->second.first, it->second.second); + //std::map >::iterator it = stackBonuses.find(Bonus::MAGIC_RESISTANCE); + //stackBonuses[Bonus::SECONDARY_SKILL_PREMY] = std::pair(it->second.first, it->second.second); if (STACK_EXP) //reading default stack experience bonuses { diff --git a/lib/CCreatureSet.cpp b/lib/CCreatureSet.cpp index ada2a051b..48867be8d 100644 --- a/lib/CCreatureSet.cpp +++ b/lib/CCreatureSet.cpp @@ -606,16 +606,16 @@ std::string CStackInstance::bonusToString(Bonus *bonus, bool description) const boost::algorithm::replace_first(text, "%d", boost::lexical_cast(valOfBonuses(Selector::typeSubtype(bonus->type, bonus->subtype)))); break; //Complex descriptions - case Bonus::SECONDARY_SKILL_PREMY: //only if there's no simple MR - if (bonus->subtype == CGHeroInstance::RESISTANCE) - { - if (!hasBonusOfType(Bonus::MAGIC_RESISTANCE)) - boost::algorithm::replace_first(text, "%d", boost::lexical_cast( magicResistance() )); - } - break; - case Bonus::MAGIC_RESISTANCE: - boost::algorithm::replace_first(text, "%d", boost::lexical_cast( magicResistance() )); - break; + //case Bonus::SECONDARY_SKILL_PREMY: //only if there's no simple MR + // if (bonus->subtype == CGHeroInstance::RESISTANCE) + // { + // if (!hasBonusOfType(Bonus::MAGIC_RESISTANCE)) + // boost::algorithm::replace_first(text, "%d", boost::lexical_cast( magicResistance() )); + // } + // break; + //case Bonus::MAGIC_RESISTANCE: + // boost::algorithm::replace_first(text, "%d", boost::lexical_cast( magicResistance() )); + // break; case Bonus::HATE: boost::algorithm::replace_first(text, "%d", boost::lexical_cast(valOfBonuses(Selector::typeSubtype(bonus->type, bonus->subtype)))); boost::algorithm::replace_first(text, "%s", VLC->creh->creatures[bonus->subtype]->namePl); @@ -658,10 +658,13 @@ std::string CStackInstance::bonusToString(Bonus *bonus, bool description) const case Bonus::SPELL_IMMUNITY: boost::algorithm::replace_first(text, "%s", VLC->spellh->spells[bonus->subtype]->name); break; - case Bonus::SECONDARY_SKILL_PREMY: - if (bonus->subtype != CGHeroInstance::RESISTANCE || hasBonusOfType(Bonus::MAGIC_RESISTANCE)) //handle it there - text = ""; + case Bonus::MAGIC_RESISTANCE: + text = ""; //handled separately break; + //case Bonus::SECONDARY_SKILL_PREMY: + // if (bonus->subtype != CGHeroInstance::RESISTANCE || hasBonusOfType(Bonus::MAGIC_RESISTANCE)) //handle it there + // text = ""; + // break; } } return text;