1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Support for Aura of Magic Resistance.

This commit is contained in:
DjWarmonger 2011-10-20 11:03:04 +00:00
parent 092dac1f63
commit bdb6db2ab7
5 changed files with 58 additions and 16 deletions

View File

@ -127,6 +127,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode *
stackNode = c;
else
stackNode = StackNode;
const CStack *battleStack = dynamic_cast<const CStack*>(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<TBonusType, std::pair<std::string, std::string> >::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<std::string>(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<const CStack*>(stackNode)) //only during battle
if (battleStack) //only during battle
{
//spell effects
int printed=0; //how many effect pics have been printed

View File

@ -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())

View File

@ -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<Bonus> & sf, const Bonus & sse);
std::vector<si32> 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

View File

@ -495,8 +495,8 @@ void CCreatureHandler::loadCreatures()
}
//handle magic resistance secondary skill premy, potentialy may be buggy
std::map<TBonusType, std::pair<std::string, std::string> >::iterator it = stackBonuses.find(Bonus::MAGIC_RESISTANCE);
stackBonuses[Bonus::SECONDARY_SKILL_PREMY] = std::pair<std::string, std::string>(it->second.first, it->second.second);
//std::map<TBonusType, std::pair<std::string, std::string> >::iterator it = stackBonuses.find(Bonus::MAGIC_RESISTANCE);
//stackBonuses[Bonus::SECONDARY_SKILL_PREMY] = std::pair<std::string, std::string>(it->second.first, it->second.second);
if (STACK_EXP) //reading default stack experience bonuses
{

View File

@ -606,16 +606,16 @@ std::string CStackInstance::bonusToString(Bonus *bonus, bool description) const
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(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<std::string>( magicResistance() ));
}
break;
case Bonus::MAGIC_RESISTANCE:
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>( 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<std::string>( magicResistance() ));
// }
// break;
//case Bonus::MAGIC_RESISTANCE:
// boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>( magicResistance() ));
// break;
case Bonus::HATE:
boost::algorithm::replace_first(text, "%d", boost::lexical_cast<std::string>(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;